import { deepCopy } from "@/plugins/utils";

const initMarkStatus = {
  structure: {
    save: false,
    sync: false,
  },
  group: {
    save: false,
    sync: false,
  },
  markerClass: {
    save: false,
    sync: false,
  },
  objective: {
    save: false,
    sync: false,
  },
  markerLeader: {
    save: false,
    sync: false,
  },
  marker: {
    save: false,
    sync: false,
  },
  answerFile: {
    save: false,
    sync: false,
  },
};

const state = {
  markParamInfos: {
    basicPaperInfo: {},
    groupInfo: [],
    classInfo: [],
    paperStructureInfo: [],
    structureCanEdit: false,
  },
  objectiveStructure: [],
  markStatus: deepCopy(initMarkStatus),
  markLeader: [],
};

const mutations = {
  setMarkParamInfos(state, data) {
    state.markParamInfos = Object.assign(
      {},
      state.markParamInfos,
      deepCopy(data)
    );
  },
  setObjectiveStructure(state, objectiveStructure) {
    state.objectiveStructure = objectiveStructure;
  },
  setMarkStatus(state, markStatus) {
    Object.keys(initMarkStatus).forEach((k) => {
      state.markStatus[k] = markStatus[k] || null;
    });
  },
  setMarkLeader(state, markLeader) {
    state.markLeader = markLeader;
  },
  initStore(state) {
    state.markParamInfos = {
      basicPaperInfo: {},
      groupInfo: [],
      classInfo: [],
      paperStructureInfo: [],
      structureCanEdit: false,
    };
    state.objectiveStructure = [];
    state.markStatus = deepCopy(initMarkStatus);
    state.markLeader = [];
  },
};

export default {
  namespaced: true,
  state,
  mutations,
};
