import { StateInterface } from './index';
import { ActionTree, MutationTree, GetterTree, Module } from 'vuex';
import { apiServer } from 'boot/axios'

export interface ExampleStateInterface {
  voiceInfo: object | null;
}

const voiceState = {
  voiceInfo: null
}

const actions: ActionTree<ExampleStateInterface, StateInterface> = {
  async getRecords({ commit }) {
    const res = await apiServer.get('/file')
    return res.data
  },
  async uploadTextSum({commit}, params) {
    const res = await apiServer.post('/nlp/textsum/', params)
    return res.data
  },
  async transText({commit}, params) {
    const res = await apiServer.post('/nlp/translate/', params)
    return res.data
  },
  async listVoice({commit}, params) {
    const res = await apiServer.get('/criminal', {params})
    return res.data
  },
  async detailVoice({commit}, params) {
    const res = await apiServer.get(`/criminal/${params.id}`)
    return res.data
  },
  async createVoice({commit}, params) {
    const res = await apiServer.post('/criminal', params)
    return res.data
  },
  async uploadSplit({commit}, params) {
    const res = await apiServer.post('/nlp/separate', params)
    return res.data
  },
  async deleteVoice({commit}, params) {
    const res = await apiServer.delete(`/criminal/${params.id}`)
    return res.data
  },
  async deleteFileVoice({commit}, params) {
    const res = await apiServer.delete(`/criminal/${params.id}/${params.file_id}`)
    return res.data
  },
  async updateVoiceInfo({commit}, params) {
    const res = await apiServer.patch(`/criminal/${params.id}`, params.data)
    return res.data
  },
  //Conversation
  async uploadConversation({commit}, params) {
    const res = await apiServer.post('/nlp/conversation', params)
    return res.data
  },
  async channelVoiceList({commit}, params) {
    const res = await apiServer.get('/conversation', {params})
    return res.data
  },
  async deleteChannelVoiceList({commit}, params) {
    const res = await apiServer.delete(`/conversation/${params.id}`)
    return res.data
  },
  async channelVoiceDetail({commit}, params) {
    const res = await apiServer.get(`/conversation/${params.id}`)
    return res.data
  },
  async restartChannelVoice({ commit }, params) {
    const res = await apiServer.get(`/nlp/conversation/${params.id}`)
    return res.data
  },
  //DETECH
  async detechVoiceList({commit}, params) {
    const res = await apiServer.get('/identification', {params})
    return res.data
  },
  async detechVoiceDetail({commit}, params) {
    const res = await apiServer.get(`/identification/${params.id}`)
    return res.data
  },
  async detechVoice({commit}, params) {
    const res = await apiServer.post('/nlp/identification', params)
    return res.data
  },
  async deleteDetechVoice({commit}, params) {
    const res = await apiServer.delete(`/identification/${params.id}`)
    return res.data
  },
  //SPLIT_VOICE
  async getListSplit({ commit }, params) {
    const res = await apiServer.get('/separate', {params})
    return res.data
  },
  async deleteListSplit({ commit }, params) {
    const res = await apiServer.delete(`/separate/${params.id}`)
    return res.data
  },
  async detailListSplit({ commit }, params) {
    const res = await apiServer.get(`/separate/${params.id}`)
    return res.data
  },
  async restartListSplit({ commit }, params) {
    const res = await apiServer.get(`/nlp/separate/${params.id}`)
    return res.data
  },
  async updateVoiceSplit({ commit }, params) {
    const res = await apiServer.put(`/criminal/${params.id}`, params.data)
    return res.data
  },
  async addCriminalToVoiceSplit({ commit }, params) {
    const res = await apiServer.put(`/separate/${params.id}/${params.criminal_id}?slot=${params.slot}`)
    return res.data
  },
};

const getters: GetterTree<ExampleStateInterface, StateInterface> = {
  getVoice: (state) => state.voiceInfo
};

const mutations: MutationTree<ExampleStateInterface> = {
  SET_VOICE(state, voiceInfo) {
    state.voiceInfo = voiceInfo
  }
};

const voiceModule: Module<ExampleStateInterface, StateInterface> = {
  namespaced: true,
  actions,
  getters,
  mutations,
  state: voiceState
};

export default voiceModule;
