export type ScoreType =
  "positive" | "negative" | "target" | "fixed_rounds" | "sudden_death";

export interface ScoringCategory {
  id: string;
  label: string;
  icon?: string; // nom d'icône lucide (ex: "TreePine") — visuel de la catégorie
  color?: string; // teinte d'accent hex pour l'icône
}

export interface GameConfig {
  id: string;
  name: string;
  minPlayers: number;
  maxPlayers: number;
  scoreType: ScoreType;
  targetScore?: number; // Used if scoreType is 'target'
  targetScoreCondition?: "reaches" | "exceeds";
  getTargetScore?: (options: Record<string, any>) => number;
  calculatePlayerTotal?: (
    rounds: Round[],
    playerId: string,
    isEndGameCalculation?: boolean,
  ) => number;
  fixedRounds?: number; // Used if scoreType is 'fixed_rounds'
  scoringCategories?: ScoringCategory[];
  // Optional: categories that depend on the chosen options (e.g. an extra
  // scoring category enabled by a rule toggle). Falls back to scoringCategories.
  getScoringCategories?: (options: Record<string, any>) => ScoringCategory[];
  description?: string;
  icon?: string;
  imagePath?: string; // Optional custom logo image (SVG, PNG, WebP...)
  bannerPath?: string; // Optional custom banner/background image
  rulesUrl?: string; // URL to a PDF or Markdown file (e.g. "/games-assets/azul-rules.pdf")
  colors: {
    primary: string;
    secondary?: string;
  };
  options?: GameOption[];
}

export interface GameOption {
  id: string;
  label: string;
  type: "boolean" | "number" | "select";
  defaultValue: any;
  options?: { label: string; value: string | number }[]; // For select type
}

export interface Player {
  id: string;
  name: string;
  color?: string;
  avatar?: string;
  linkedUserId?: string; // compte serveur de l'ami tagué comme co-joueur (Phase 4)
}

export interface RoundScore {
  playerId: string;
  score: number;
  details?: Record<string, any>;
  caboCall?: "success" | "fail"; // For Cabo game specifically
  kamikaze?: boolean; // For Cabo Kamikaze rule
}

export interface Round {
  id: string;
  roundNumber: number;
  scores: RoundScore[];
}

export interface GameSession {
  id: string;
  gameId: string;
  dateStart: number;
  dateEnd?: number;
  players: Player[];
  rounds: Round[];
  status: "playing" | "finished";
  options: Record<string, any>;
  winnerIds?: string[];
  locationId?: string;
  profileId: string;
  updatedAt: number;
  deletedAt?: number; // tombstone pour la synchronisation
  dirty?: number; // 1 = modifié localement, à pousser (0/absent = synchronisé)
}

export interface AppSettings {
  id: number;
  theme: "light" | "dark" | "system";
  language: string;
  activeProfileId: string;
}

export interface SavedPlayer {
  id: string;
  name: string;
  createdAt: number;
  updatedAt: number;
  avatar?: string;
  profileId: string;
  linkedProfileId?: string; // réservé pour la Phase 4 (lien vers un ami)
  deletedAt?: number; // tombstone pour la synchronisation
  dirty?: number; // 1 = modifié localement, à pousser
}

export interface Location {
  id: string;
  name: string;
  address?: string;
  createdAt: number;
  updatedAt: number;
  deletedAt?: number; // tombstone pour la synchronisation
  profileId: string;
  dirty?: number; // 1 = modifié localement, à pousser
}

export interface SyncState {
  profileId: string;
  lastSyncedAt: number;
}

export interface Profile {
  id: string;
  name: string;
  avatar?: string;
  createdAt: number;
  updatedAt: number;
  remoteUserId?: string; // réservé pour la Phase 3 (compte serveur)
}
