import { EventEmitter } from "events";

export const serverEvents = new EventEmitter();

serverEvents.setMaxListeners(50);

// Debug logging for listener count
if (process.env.NODE_ENV === 'development') {
  setInterval(() => {
    const listenerCounts = {
      test: serverEvents.listenerCount('test'),
      match: serverEvents.listenerCount('match'),
      reaction: serverEvents.listenerCount('reaction'),
    };

    if (listenerCounts.test > 0 || listenerCounts.match > 0 || listenerCounts.reaction > 0) {
      console.log('ServerEvents listener count:', listenerCounts);
    }
  }, 30000); // Log every 30 seconds in development
}

export type TestEvent = {
  type: "test";
  playerId: string;
};

export type MatchEvent = {
  type: "match";
  matchId: string;
  tournamentId: string;
}

export type ReactionEvent = {
  type: "reaction";
  matchId: string;
}

export type ServerEvent = TestEvent | MatchEvent | ReactionEvent;
