import { getPermission,savePermission,checkPermission } from '@/services/permission';

export default{
  namespace: 'permissionModel',
  state: {
    data: [],
  },
  effects: {
    *getAccountPermission({callback,payload},{ call, put }) {
      const response = yield call(getPermission,payload);
      yield put({
        type: "get",
      });
      if(callback) callback(response);
    },
    *saveAccountPermission({callback,payload},{ call, put }) {
      const response = yield call(savePermission,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },
    *checkAccountPermission({callback,payload},{ call, put }) {
      const response = yield call(checkPermission,payload);
      yield put({
        type: "check",
      });
      if(callback) callback(response);
    },
  },
  reducers: {
    get(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    save(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    check(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
  },
};
