import { Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Interval } from 'date-fns';
import { TicketLifecycleService } from './ticket-lifecycle.service';
import {
  TicketSystemEventTypes,
  TicketSystemValidatedEvent,
} from './ticket-system.events';

@Injectable()
export class TicketService {
  constructor(
    private readonly lifecycle: TicketLifecycleService,
    private readonly eventEmitter: EventEmitter2,
  ) {}

  async createTickets(interval: Interval): Promise<void> {
    await this.lifecycle.createTickets(interval);

    this.eventEmitter.emit(
      TicketSystemEventTypes.Validated,
      new TicketSystemValidatedEvent(0),
    );
  }
}
