export type GameTurn = 'white' | 'black';

export interface ClockState {
  whiteRemainingMs: number;
  blackRemainingMs: number;
}

export type GameStatus =
  | 'started'
  | 'check'
  | 'checkmate'
  | 'stalemate'
  | 'resign'
  | 'draw'
  | 'drawOffered'
  | 'fiftyMoveAvailable'
  | 'promotionPending'
  | 'insufficientMaterial';

export interface PlayerInfo {
  id: string;
  displayName: string;
}

export interface GameState {
  fen: string;
  pgn: string;
  turn: GameTurn;
  status: GameStatus;
  winner?: GameTurn | null;
  moves: string[];
  undoAvailable: boolean;
  redoAvailable: boolean;
  clock: ClockState | null;
}

export interface GameFull {
  gameId: string;
  white: PlayerInfo;
  black: PlayerInfo;
  state: GameState;
}

export interface LegalMove {
  from: string;
  to: string;
  uci: string;
  moveType: string;
  promotion?: 'queen' | 'rook' | 'bishop' | 'knight' | null;
}

export interface LegalMovesResponse {
  moves: LegalMove[];
}

export interface ApiError {
  code: string;
  message: string;
  field?: string | null;
}

export interface GameFullEvent {
  type: 'gameFull';
  game: GameFull;
}

export interface GameStateEvent {
  type: 'gameState';
  state: GameState;
}

export interface ErrorEvent {
  type: 'error';
  error: ApiError;
}

export type GameStreamEvent = GameFullEvent | GameStateEvent | ErrorEvent;
