import {
  ITicketRepository,
  TicketRepository,
} from "../repositories/ticket-repositories";
import * as uuidv4 from "uuid";
import { Ticket, TicketType } from "../common/common-types";

interface ITicketService {
  repository: ITicketRepository;
}

class TicketService implements ITicketService {
  repository: ITicketRepository;
  constructor(knex: any) {
    this.repository = new TicketRepository(knex);
  }

  async create(data: Ticket) {
    const newId = uuidv4();
    await this.repository.create(newId, data);
    return newId;
  }

  createMultiple(data: Ticket[]) {
    return this.repository.createMultiple(data);
  }

  delete(id: string) {
    return this.repository.delete(id);
  }

  deleteAllTickets() {
    return this.repository.deleteAllTickets();
  }

  validate(id: string) {
    return this.repository.validate(id);
  }

  async createTicketType(data: TicketType) {
    const newId = uuidv4();
    await this.repository.createType(newId, data);
    return { newId, data };
  }

  deleteTicketType(id: string) {
    return this.repository.deleteTicketType(id);
  }

  deleteAllTicketTypes() {
    return this.repository.deleteAllTicketTypes();
  }

  getAllTicketTypes() {
    return this.repository.getAllTicketTypes();
  }
}

export default TicketService;
