export interface Campaign {
  id: number;
  name: string;
  role?: string;
  created_at: string;
}

export interface Stat {
  stat_name: string;
  value: number;
}

export interface Gear {
  id: number;
  character_id: number;
  name: string;
  type: "weapon" | "armor" | "gear" | "spell";
  slot_count: number;
  properties: Record<string, unknown>;
  effects: Record<string, unknown>;
  game_item_id: number | null;
}

export interface Talent {
  id: number;
  character_id: number;
  name: string;
  description: string;
  effect: Record<string, unknown>;
  game_talent_id: number | null;
}

export interface Character {
  id: number;
  campaign_id: number;
  user_id?: number | null;
  created_by: string;
  name: string;
  class: string;
  ancestry: string;
  level: number;
  xp: number;
  hp_current: number;
  hp_max: number;
  ac: number;
  alignment: string;
  title: string;
  notes: string;
  background: string;
  deity: string;
  languages: string;
  gp: number;
  sp: number;
  cp: number;
  gear_slots_max: number;
  overrides: Record<string, unknown>;
  color: string;
  luck_token: number;
  torch_lit_at: string | null;
  stats: Stat[];
  gear: Gear[];
  talents: Talent[];
}

export interface GameItem {
  id: number;
  name: string;
  type: "weapon" | "armor" | "gear";
  slot_count: number;
  effects: Record<string, unknown>;
  properties: Record<string, unknown>;
}

export interface GameTalent {
  id: number;
  name: string;
  source: string;
  description: string;
  effect: Record<string, unknown>;
}

export interface AttackLine {
  name: string;
  modifier: number;
  modifierStr: string;
  damage: string;
  tags: string[];
  isTalent: boolean;
  description?: string;
}

export interface RollResult {
  id: number;
  campaign_id: number;
  character_id: number | null;
  character_name: string;
  character_color: string;
  type: "attack" | "ability-check" | "custom";
  subtype?: string;
  label: string;
  dice_expression: string;
  rolls: number[];
  modifier: number;
  total: number;
  advantage: boolean;
  disadvantage: boolean;
  nat20: boolean;
  undone?: boolean;
  created_at: string;
}

export interface Spell {
  id: number;
  name: string;
  class: "wizard" | "priest" | "both";
  tier: number;
  casting_stat: "INT" | "WIS";
  duration: string;
  range: string;
  is_focus: number;
  description: string;
}

export interface CharacterSpell {
  id: number;
  spell_id: number;
  character_id?: number;
  exhausted: number;
  locked_until: string | null;
  focus_active: number;
  focus_started_at: string | null;
  name: string;
  class: "wizard" | "priest" | "both";
  tier: number;
  casting_stat: "INT" | "WIS";
  duration: string;
  range: string;
  is_focus: number;
  description: string;
}

export interface SpellCastResult {
  rollId: number;
  roll: number;
  modifier: number;
  total: number;
  dc: number;
  result: "success" | "failure" | "crit_success" | "crit_fail";
  mishapResult: Record<string, unknown> | null;
}

export interface Condition {
  id: number;
  character_id: number;
  name: string;
  description: string;
  rounds_remaining: number | null;
  expires_at: string | null;
}

export interface CombatEnemy {
  id: string;
  name: string;
  hp_current?: number;  // present only for DM; stripped before broadcast to players
  hp_max?: number;      // present only for DM; stripped before broadcast to players
}

export interface CombatState {
  id: string;
  label?: string;
  mode: "team";
  round: number;
  phase: "rolling" | "active";
  current_side: "party" | "enemies";
  party_roll: number | null;
  enemy_roll: number | null;
  party_rolls: Record<number, number>;  // characterId → roll value
  character_ids: number[];
  enemies: CombatEnemy[];
}
