import axios from 'axios'

export default {
  namespaced: true,
  state: {

  },
  mutations: {

  },
  actions: {
    async addParam ({state}, data) {
      await axios.post('/paramsSetting', data)
    },
    async addRecord ({state}, {id, recordData}) {
      await axios.post(`paramsSetting/${id}/record`, recordData)
    },
    async lookUpListAndStore ({rootState, commit}) { // 全部
      await axios.get('/paramsSetting', {
        params: {
          projectId: rootState.project.current._id
        }
      })
    },
    async lookupParam ({rootState, dispatch}, name) { // 查詢單筆參數(projectId, name)
      let result = await axios.get(`/paramsSetting/projectId/${rootState.project.current._id}/${name}`)
      return result.data
    },
    async updateParam ({state}, {id, paramsValue}) { // 修改
      await axios.patch(`paramsSetting/${id}`, paramsValue)
    },
    async updateParamsItem ({state}, {id, paramsItems}) { // 修改
      await axios.patch(`paramsSetting/${id}/paramsItems`, paramsItems)
    }
  }
}
