import { getAccount,delAccount,saveAccount,getAllLeader,checkAccountByName,quitAndUser } from '@/services/account';

export default{
  namespace: 'accountModel',
  state: {
    data: [],
  },
  effects: {
    *getAccount({callback,payload},{ call, put }) {
      const response = yield call(getAccount,payload);
      yield put({
        type: "getUsers",
      });
      if(callback) callback(response);
    },
    *saveAccount({callback,payload},{ call, put }) {
      const response = yield call(saveAccount,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },
    *delAdccount({callback,payload},{ call, put }) {
      const response = yield call(delAccount,payload);
      yield put({
        type: "del",
      });
      if(callback) callback(response);
    },
    *getAllLeader({callback,payload},{ call, put }) {
      const response = yield call(getAllLeader,payload);
      yield put({
        type: "allLeader",
      });
      if(callback) callback(response);
    },
    *checkAccountByName({callback,payload},{ call, put }) {
      const response = yield call(checkAccountByName,payload);
      yield put({
        type: "checkUser",
      });
      if(callback) callback(response);
    },
    *quitAndUser({callback,payload},{ call, put }) {
      const response = yield call(quitAndUser,payload);
      yield put({
        type: "quitUser",
      });
      if(callback) callback(response);
    },
  },
  reducers: {
    allLeader(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    getUsers(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    save(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    del(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    checkUser(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    quitUser(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
  },
};
