import {
  FETCH_CAR_PLATE,
  FETCH_CAR_CATEGORY,
  FETCH_REPAIR_AREA,
  FETCH_REPAIR_TERM,
  FETCH_ALL_AUTH_USER,
} from './mutation-types';
import { getBaseData, getUserList } from '@/api/base/base';

const state = () => ({
  carPlate: [],
  carCategory: [],
  repairArea: [],
  repairTerm: [],
  authUserList: [],
});

const getters = {
  carPlateOptions: state => state.carPlate,
  carCategoryOptions: state => state.carCategory,
  repairAreaOptions: state => state.repairArea,
  repairTermOptions: state => state.repairTerm,
  authUserList: state => state.authUserList,
};

const actions = {
  fetchCarPlateOptions({ commit }) {
    getBaseData({
      type: '4',
    }).then(res => {
      commit(FETCH_CAR_PLATE, res.data);
    });
  },
  fetchCarCategoryOptions({ commit }) {
    getBaseData({
      type: '3',
    }).then(res => {
      commit(FETCH_CAR_CATEGORY, res.data);
    });
  },
  fetchRepairAreaOptions({ commit }) {
    getBaseData({
      type: '1',
    }).then(res => {
      commit(FETCH_REPAIR_AREA, res.data);
    });
  },
  fetchRepairTermOptions({ commit }) {
    getBaseData({
      type: '2',
    }).then(res => {
      commit(FETCH_REPAIR_TERM, res.data);
    });
  },
  fetchAllAuthUserList({ commit }) {
    getUserList().then(res => {
      commit(FETCH_ALL_AUTH_USER, res.data);
    });
  },
};
const mutations = {
  [FETCH_CAR_PLATE](state, list) {
    state.carPlate = list;
  },
  [FETCH_CAR_CATEGORY](state, list) {
    state.carCategory = list;
  },
  [FETCH_REPAIR_AREA](state, list) {
    state.repairArea = list;
  },
  [FETCH_REPAIR_TERM](state, list) {
    state.repairTerm = list;
  },
  [FETCH_ALL_AUTH_USER](state, list) {
    state.authUserList = list;
  },
};
export default {
  state,
  getters,
  actions,
  mutations,
};
