// ============================================
// Kuldvillak (Jeopardy) Type Definitions
// ============================================

/** A single question/answer pair on the board */
export interface Question {
    id: string;
    question: string;
    answer: string;
    points: number;
    isDailyDouble: boolean;
    isRevealed: boolean;
    imageUrl?: string;
}

/** A category column containing questions */
export interface Category {
    id: string;
    name: string;
    questions: Question[];
}

/** A game round (e.g., Jeopardy, Double Jeopardy) */
export interface Round {
    id: string;
    name: string;
    categories: Category[];
    pointMultiplier: number;
}

/** Final Jeopardy round structure */
export interface FinalRound {
    category: string;
    question: string;
    answer: string;
}

/** A competing team */
export interface Team {
    id: string;
    name: string;
    score: number;
}

/** Current game phase */
export type GamePhase =
    | 'intro'              // Show Kuldvillak home screen (round start)
    | 'intro-categories'   // Animating category introductions
    | 'lobby'
    | 'board'
    | 'question'
    | 'answer'
    | 'daily-double'
    | 'final-intro'        // Final round intro (Kuldvillak screen)
    | 'final-category'     // Reveal final round category
    | 'final-wagers'       // Collect wagers from each team
    | 'final-question'
    | 'final-reveal'
    | 'final-scores'
    | 'finished';

/** Result of a question for tracking */
export interface QuestionResult {
    categoryIndex: number;
    questionIndex: number;
    points: number;
    teamId: string | null;       // Who won/lost points (null if skipped)
    pointsChange: number;        // Positive for correct, negative for wrong, 0 for skip
    isDailyDouble: boolean;
    wager?: number;              // DD wager if applicable
}

/** Current state during gameplay */
export interface GameState {
    phase: GamePhase;
    currentRoundIndex: number;
    currentQuestionId: string | null;
    currentCategoryId: string | null;
    activeTeamId: string | null;
    dailyDoubleWager: number | null;
    finalWagers: Record<string, number>;
    finalAnswers: Record<string, string>;
}

/** Point value preset types */
export type PointValuePreset = 'round1' | 'round2' | 'custom' | 'multiplier';

/** Configurable game settings */
export interface GameSettings {
    numberOfRounds: 1 | 2;
    pointValuePreset: PointValuePreset;
    pointValues: number[];
    basePointValue: number; // For multiplier preset (e.g., 100 → 100,200,300,400,500)
    categoriesPerRound: number;
    questionsPerCategory: number;
    dailyDoublesPerRound: number[];
    enableFinalRound: boolean;
    enableSoundEffects: boolean;
    allowNegativeScores: boolean;
    maxTeams: number;
    defaultTimerSeconds: number;
    answerRevealSeconds: number;
}

/** Point value presets */
export const POINT_PRESETS = {
    round1: [100, 200, 300, 400, 500],
    round2: [200, 400, 600, 800, 1000]
} as const;

/** Complete game configuration (saveable/loadable) */
export interface KuldvillakGame {
    id: string;
    name: string;
    createdAt: string;
    updatedAt: string;
    settings: GameSettings;
    teams: Team[];
    rounds: Round[];
    finalRound: FinalRound | null;
    state: GameState;
}

/** Default settings for new games */
export const DEFAULT_SETTINGS: GameSettings = {
    numberOfRounds: 2,
    pointValuePreset: 'round1',
    pointValues: [10, 20, 30, 40, 50],
    basePointValue: 10,
    categoriesPerRound: 6,
    questionsPerCategory: 5,
    dailyDoublesPerRound: [1, 2],
    enableFinalRound: true,
    enableSoundEffects: true,
    allowNegativeScores: true,
    maxTeams: 6,
    defaultTimerSeconds: 5,
    answerRevealSeconds: 5
};

/** Default initial game state */
export const DEFAULT_STATE: GameState = {
    phase: 'lobby',
    currentRoundIndex: 0,
    currentQuestionId: null,
    currentCategoryId: null,
    activeTeamId: null,
    dailyDoubleWager: null,
    finalWagers: {},
    finalAnswers: {}
};

// ============================================
// Helper Types for Editor/UI
// ============================================

/** Saved game metadata for game list */
export interface GameMetadata {
    id: string;
    name: string;
    createdAt: string;
    updatedAt: string;
    teamCount: number;
    roundCount: number;
}

/** View mode for dual-screen setup */
export type ViewMode = 'projector' | 'moderator';