import Ticket from "../../models/Ticket";
import AppError from "../../errors/AppError";

import { deleteTicketsByIdCache } from '../../helpers/TicketCache'

const DeleteTicketService = async (id: string): Promise<Ticket> => {
  const ticket = await Ticket.findOne({
    where: { id }
  });

  if (!ticket) {
    throw new AppError("ERR_NO_TICKET_FOUND", 404);
  }

  await ticket.destroy(); 

  // TEST DEL
  await deleteTicketsByIdCache(id)
  //

  return ticket;
};

export default DeleteTicketService;