import {getRelatedCaseAll} from "@/api/business/crm/paraRelatedCase/relatedCase";

const relatedCase = {
  state: {
    lastUpdate: null,
    cases: {},
  },

  mutations: {
    SET_CASES: (state, {lastUpdate, cases}) => {
      state.lastUpdate = lastUpdate
      if (cases) {
        state.cases = cases
      }
    },
  },

  actions: {
    loadCases({commit}){
      return new Promise((resolve, reject) => {
        getRelatedCaseAll({lastUpdate: relatedCase.state.lastUpdate}).then(res => {
          commit('SET_CASES', res.data)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    },
  }
}

export default relatedCase
