import pagination from '../../../store/modules/pagination';
import { fetchTeacherList } from '@/api/management/user';
import { GET_USER_LIST } from './mutation-types';

const state = {
  list: [],
};
const getters = {
  userList: state => state.list,
};
const actions = {
  fetchUserList({ dispatch, state, commit }, entity) {
    return fetchTeacherList({
      ...state.pagination,
      ...entity,
    }).then(res => {
      const { list, ...pagination } = res.data;
      dispatch('updatePagination', pagination);
      commit(GET_USER_LIST, list);
    });
  },
};
const mutations = {
  [GET_USER_LIST](state, list) {
    state.list = list;
  },
};

export default {
  namespaced: true,
  modules: {
    pagination,
  },
  state,
  getters,
  actions,
  mutations,
};