export interface GamePlugin<TState = unknown, TAction = unknown> {
    slug: string;
    name: string;
    minPlayers: number;
    maxPlayers: number;

    createInitialState(players: string[]): TState;
    handleAction(state: TState, action: TAction, playerId: string): GameResult<TState>;
    getPlayerView(state: TState, playerId: string): unknown;
    getSpectatorView(state: TState): unknown;

    isGameOver?(state: TState): GameOverResult | null;
    onPlayerDisconnect?(state: TState, playerId: string): TState;
}

export type GameResult<TState> =
    | { ok: true; state: TState }
    | { ok: false; error: string };

export type GameOverResult = {
    winner: string | null;
    reason: string;
};
