import {
  LeagueEventPublisher,
  LeagueCreatedEvent,
  LeagueUpdatedEvent,
  LeagueDeletedEvent,
  LeagueAccessedEvent,
} from '../../../core/leagues/application/ports/LeagueEventPublisher';

export class InMemoryLeagueEventPublisher implements LeagueEventPublisher {
  private leagueCreatedEvents: LeagueCreatedEvent[] = [];
  private leagueUpdatedEvents: LeagueUpdatedEvent[] = [];
  private leagueDeletedEvents: LeagueDeletedEvent[] = [];
  private leagueAccessedEvents: LeagueAccessedEvent[] = [];

  async emitLeagueCreated(event: LeagueCreatedEvent): Promise<void> {
    this.leagueCreatedEvents.push(event);
  }

  async emitLeagueUpdated(event: LeagueUpdatedEvent): Promise<void> {
    this.leagueUpdatedEvents.push(event);
  }

  async emitLeagueDeleted(event: LeagueDeletedEvent): Promise<void> {
    this.leagueDeletedEvents.push(event);
  }

  async emitLeagueAccessed(event: LeagueAccessedEvent): Promise<void> {
    this.leagueAccessedEvents.push(event);
  }

  getLeagueCreatedEventCount(): number {
    return this.leagueCreatedEvents.length;
  }

  getLeagueUpdatedEventCount(): number {
    return this.leagueUpdatedEvents.length;
  }

  getLeagueDeletedEventCount(): number {
    return this.leagueDeletedEvents.length;
  }

  getLeagueAccessedEventCount(): number {
    return this.leagueAccessedEvents.length;
  }

  clear(): void {
    this.leagueCreatedEvents = [];
    this.leagueUpdatedEvents = [];
    this.leagueDeletedEvents = [];
    this.leagueAccessedEvents = [];
  }

  getLeagueCreatedEvents(): LeagueCreatedEvent[] {
    return [...this.leagueCreatedEvents];
  }

  getLeagueUpdatedEvents(): LeagueUpdatedEvent[] {
    return [...this.leagueUpdatedEvents];
  }

  getLeagueDeletedEvents(): LeagueDeletedEvent[] {
    return [...this.leagueDeletedEvents];
  }

  getLeagueAccessedEvents(): LeagueAccessedEvent[] {
    return [...this.leagueAccessedEvents];
  }
}
