import { TicketsService } from '@services/tickets-service';
import { ActionContext, ActionTree, mapActions } from 'vuex';

export const state = {};

export const getters = {};

export const mutations = {};

export const actions: ActionTree<any, any> = {
  fetchTicket(
    { commit }: ActionContext<any, any>,
    { id, useAuth = true } = {}
  ) {
    return TicketsService.handler({ useAuth }).then((ticketsApi) => {
      return ticketsApi.ticketGet(id);
    });
  },
  updateTicketStatus(
    { commit }: ActionContext<any, any>,
    { id, statusCode, useAuth = true } = {}
  ) {
    return TicketsService.handler({ useAuth }).then((ticketsApi) => {
      return ticketsApi.ticketUpdateStatus({ bookId: id, statusCode });
    });
  },
};

export const ticketsServiceMethods = mapActions('ticketsService/tickets', [
  'fetchTicket',
  'updateTicketStatus',
]);
