import { api } from 'src/boot/axios';
import { ActionTree } from 'vuex';
import { run } from '../helpers';
import { ProductoHoldersState } from './ProductoHoldersState';

export const actions: ActionTree<ProductoHoldersState, unknown> = {
  getList: async ({ state, commit }, id) => {
    state.loading = true;
    run(api.get(`producto/${id}/holders`))
      .then((data) => commit('setList', data))
      .finally(() => (state.loading = false));
  },
  refreshList: async ({ state, commit }) => {
    state.loading = true;
    run(
      api.get(`producto/holders`, {
        params: state.queryParams,
      })
    )
      .then((data) => commit('setList', data))
      .finally(() => (state.loading = false));
  },
};
