import type { Socket } from 'socket.io';
import type { TokenBucket } from '../rateLimit';

export type Identity =
  | { role: 'guest'; playerId: string; gameSessionId: string }
  | { role: 'tv' }
  | { role: 'host'; venueUserId: string; venueId: string; eventId: string | null }
  | { role: 'anon' };

export interface Attached {
  socket: Socket;
  identity: Identity;
  ip: string;
  bucket: TokenBucket;
}

/** Shape of `socket.handshake.auth` sent by web clients. */
export interface HandshakeAuth {
  /** Guest tokens for this room (one per game session joined). The server picks the best one. */
  tokens?: string[];
  token?: string;
  tvToken?: string;
  hostToken?: string;
  /** Host sockets: the event being controlled. */
  eventId?: string;
}

export type AckFn<T = unknown> = (res: { ok: true; data?: T } | { ok: false; error: { code: string; message: string } }) => void;
