// ── op.gg MCP response types ──

export interface RegionInfo {
  code: string;   // "EUW", "NA", "KR", etc.
  label: string;  // "EU West", "North America", etc.
}

// ── Summoner Profile ──

export interface TierInfo {
  tier: string | null;       // "GOLD", "GRANDMASTER", etc.
  division: number | null;   // 1,2,3,4
  lp: number | null;
  tier_image_url?: string;
}

export interface LeagueStat {
  game_type: string;        // "SOLORANKED", "FLEXRANKED", "ARENA"
  win: number | null;
  lose: number | null;
  is_hot_streak: boolean;
  tier_info: TierInfo;
}

export interface LadderRank {
  rank: number | null;
  total: number | null;
}

export interface ChampionStat {
  champion_name: string;
  id: number;
  play: number;
  win: number;
  lose: number;
  kill: number;
  death: number;
  assist: number;
}

export interface MostChampions {
  game_type: string;
  play: number;
  win: number;
  lose: number;
  champion_stats: ChampionStat[];
}

export interface SummonerProfile {
  game_name: string;
  tagline: string;
  level: number;
  profile_image_url: string;
  league_stats: LeagueStat[];
  ladder_rank: LadderRank;
  most_champions: MostChampions;
  updated_at: string;
}

// ── Match History ──

export interface MatchParticipantStats {
  kill: number;
  death: number;
  assist: number;
  minion_kill: number;
  neutral_minion_kill: number;
  gold_earned: number;
  total_damage_dealt_to_champions: number;
  total_damage_taken: number;
  ward_place: number;
  vision_wards_bought_in_game: number;
  champion_level: number;
  op_score: number;
  op_score_rank: number;
  result: string;  // "WIN" | "LOSE"
}

export interface MatchParticipant {
  champion_name: string;
  champion_id: number;
  items: number[];
  items_names: string[];
  position: string;       // "TOP", "JUNGLE", "MID", "ADC", "SUPPORT"
  team_key: string;       // "BLUE" | "RED"
  spells: number[];
  stats: MatchParticipantStats;
  summoner: {
    game_name: string;
    tagline: string;
    puuid?: string;
  };
}

export interface TeamStat {
  key: string;  // "BLUE" | "RED"
  banned_champions_names: string[];
  game_stat: {
    is_win: boolean;
    baron_kill: number;
    dragon_kill: number;
    tower_kill: number;
    champion_kill: number;
    gold_earned: number;
    inhibitor_kill: number;
    rift_herald_kill: number;
  };
}

export interface MatchEntry {
  id: string;
  created_at: string;
  game_length_second: number;
  game_type: string;      // "SOLORANKED", "FLEXRANKED", "NORMAL", "ARAM"
  game_map: string;
  average_tier_info?: { tier: string; division: number };
  participants: MatchParticipant[];
  teams: TeamStat[];
}

// ── Composite types for API responses ──

export interface ProfileResponse {
  summoner: SummonerProfile;
}

export interface MatchHistoryResponse {
  matches: MatchEntry[];
}

export interface MatchDetailResponse {
  match: MatchEntry;
}

// ── Recent search persistence ──

export interface RecentSearch {
  game_name: string;
  tag_line: string;
  region: string;
  profile_image_url: string;
  level: number;
  tier?: string;
  rank?: string;
  timestamp: number;
}
