import { ScoreType, ScoringCategory, GameOption } from "./index";

// How a player's total is computed from their per-round scores. Declarative so
// imported game files never carry executable code.
export type ScoreFormula =
  | { strategy: "sum_rounds" }
  | {
      strategy: "sum_rounds_with_reset";
      resetThreshold: number;
      resetTo: number;
      oncePerPlayer?: boolean;
    };

// How the end-of-game target score is resolved.
export type TargetScoreSpec =
  | { type: "fixed"; value: number }
  | {
      type: "fromOption";
      optionId: string;
      customOptionId?: string;
      customSentinel?: string;
    };

// The importable game definition (a single JSON file, images embedded as data URIs).
export interface ImportedGameDefinition {
  schemaVersion: 1;
  id: string;
  name: string;
  minPlayers: number;
  maxPlayers: number;
  scoreType: ScoreType;
  scoreFormula: ScoreFormula;
  targetScore?: TargetScoreSpec;
  targetScoreCondition?: "reaches" | "exceeds";
  fixedRounds?: number;
  scoringCategories?: ScoringCategory[];
  options?: GameOption[];
  description?: string;
  colors: { primary: string; secondary?: string };
  icon?: string; // nom d'icône lucide (utilisé si aucune iconImage n'est fournie)
  iconImage?: string; // data URI (png/svg/webp) -> imagePath
  bannerImage?: string; // data URI -> bannerPath
}

// As stored in Dexie, scoped to a local profile.
export interface ImportedGame extends ImportedGameDefinition {
  profileId: string;
  createdAt: number;
  updatedAt: number;
}

// Ids reserved by the built-in games; imported games may not reuse them.
export const RESERVED_GAME_IDS = [
  "azul",
  "cabo",
  "skyjo",
  "harmonie",
  "odin_cards",
];
