import {fetchTaskAuth} from "@/api/process/task";

const process = {
  state: {
    permissions: [],
    projectTab: {
      status: null,
      projectType: null
    }
  },
  mutations: {
    SET_PROCESS_PERMISSIONS: (state, permissions) => {
      state.permissions = permissions
    },
    SET_PROJECT_TAB_STATUS: (state, { status, projectType }) =>{
      state.projectTab.projectType = projectType
      state.projectTab.status = status
    }
  },
  actions: {
    GetProcessPermissions({ commit, state }, {  projectId, taskId, instanceId }) {
      return new Promise((resolve, reject) => {
        fetchTaskAuth({ projectId, taskId , id: instanceId }).then(({ data }) => {
          const permissions = data && data.permissions || []
          commit('SET_PROCESS_PERMISSIONS', permissions)
          resolve(permissions)
        })
      })
    }
  }
}

export default process
