/* eslint-disable @typescript-eslint/no-explicit-any */
import { StateInterface } from './index';
import { ActionTree, MutationTree, GetterTree, Module } from 'vuex';
import { apiServer } from 'boot/axios';
export interface SlotStateInterface {
  reserveDialog: boolean;
  currentId: number;
}

const slotState: SlotStateInterface = {
  reserveDialog: false,
  currentId: 1,
};
const actions: ActionTree<SlotStateInterface, StateInterface> = {
  async getListSlot({ }, params: any) {
    const res = await apiServer.get('/slot', { params: params });
    return res.data;
  },
  async getListSlotByCursor({ }, params: any) {
    const res = await apiServer.get('/slot/cursor', { params: params });
    return res.data;
  },
  async getListSlotNear({ }, params: any) {
    const res = await apiServer.get('/slot/near', {
      params: { ...params, ...{ radius: 1 } },
    });
    return res.data;
  },
  async detailSlot({ }, params: any) {
    const res = await apiServer.get(`/slot/${params.id}`);
    return res.data;
  },
  async bookingSlot({ }, params: any) {
    const res = await apiServer.post('/booking-slot', params);
    return res.data;
  },
  async addSlot({ }, params: any) {
    const res = await apiServer.post('/slot', params);
    return res.data;
  },
  async updateSlot({ }, params: any) {
    const res = await apiServer.patch(`/slot/${params.id}`, params);
    return res.data;
  },
  async historyBookingSlot({ }, params: any) {
    const res = await apiServer.get('booking-slot/history', {
      params: { ...params },
    });
    return res.data;
  },
  async submitBookingSlot({ }, params: any) {
    const res = await apiServer.get(`booking-slot/submit/${params.id}`);
    return res.data;
  },
  async outBookingSlot({ }, params: any) {
    const res = await apiServer.get(`booking-slot/out/${params.id}`);
    return res.data;
  },
  async myPacking({ }, params: any) {
    const res = await apiServer.get('/slot/user', params);
    return res.data;
  },
  async rateSlot({ }, params: any) {
    const data = params.data;
    const res = await apiServer.post(`/slot/vote/${params.id}`, data);
    return res;
  },
  async getRateSlot({ }, params: any) {
    const res = await apiServer.get(`/slot/vote/${params}`);
    return res.data;
  },
  changeReserveDialog({ commit, state }) {
    commit('SET_RESERVEDIALOG', !state.reserveDialog);
  },
  changeCurrentId({ commit }, value) {
    commit('SET_ID', value);
  },
};

const getters: GetterTree<SlotStateInterface, StateInterface> = {
  getReserveDialog: (state) => state.reserveDialog,
  getCurrentId: (state) => state.currentId,
};

const mutations: MutationTree<SlotStateInterface> = {
  SET_RESERVEDIALOG(state, reserveDialog) {
    state.reserveDialog = reserveDialog;
  },
  SET_ID(state, value) {
    state.currentId = value;
  },
};
const slotModule: Module<SlotStateInterface, StateInterface> = {
  namespaced: true,
  actions,
  getters,
  mutations,
  state: slotState,
};

export default slotModule;
