import aoiGql from '@/gql/aoi'
import wpoService from '@/service/wpo'

const state = {
    aoi: {},
    serial: '',    
}

const getters = {
}

const actions = {
    async getSerial({commit}){
        let serial = await wpoService.getWpoId()  //웹서버에 지정한 WPO ID 가져오기
        commit('GETSERIAL' , serial)
    },

    async getAoi({commit}, serial){
        let aoi = await aoiGql.get(serial)        

        commit('GETAOI' , aoi)
    },

    async updateAoi({commit} , input){
        let result = await aoiGql.update(input)

        commit('UPDATEAOI' , result)
    },
}

const mutations = {
    GETSERIAL(state,payload ){
        state.serial = payload
    },

    GETAOI(state,payload ){
        state.aoi = payload
    },
    
    UPDATEAOI(state,payload){
        state.aoi = { ...payload}; 
    },
}

export default {
    state: {
        ...state
    },
    getters,
    mutations,
    actions
}