// ============================================
// 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 round intro screen (Villak/Topeltvillak)
    | 'intro-categories'   // Animating category introductions
    | 'board'              // Main game board with questions
    | 'question'           // Displaying a question
    | 'daily-double'       // Daily double wager selection
    | 'final-intro'        // Final round intro (Kuldvillak screen)
    | 'final-category'     // Reveal final round category
    | 'final-question'     // Final round question display
    | 'final-scores'       // Final scores display
    | 'finished';          // Game complete

/** 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
}

/** Point value preset types
 * - round1: Base points (10-50) multiplied by round number
 * - custom: User-defined point values
 */
export type PointValuePreset = 'round1' | 'custom';

/** Configurable game settings */
export interface GameSettings {
    numberOfRounds: 1 | 2;
    pointValuePreset: PointValuePreset;
    pointValues: number[];
    categoriesPerRound: number;
    questionsPerCategory: number;
    dailyDoublesPerRound: number[];
    enableFinalRound: boolean;
    enableSoundEffects: boolean;
    allowNegativeScores: boolean;
    maxTeams: number;
    defaultTimerSeconds: number;
    answerRevealSeconds: number;
}

/** Minimal state stored with saved games (not used during gameplay) */
export interface SavedGameState {
    phase: GamePhase;
    currentRoundIndex: number;
}

/** 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: SavedGameState;
}

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

/** Default initial game state for saved games */
export const DEFAULT_STATE: SavedGameState = {
    phase: 'intro',
    currentRoundIndex: 0
};

// ============================================
// 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;
}