// ========================
// Enums & Constants
// ========================

export type SportType = "football" | "basketball";

export type MatchStatus =
  | "LIVE"
  | "Finished"
  | "Not Started"
  | "UPCOMING"
  | "NOT_STARTED"
  | string;

// ========================
// Query DTOs
// ========================

export interface TeamFilterDto {
  name?: string;
  id?: string;
}

export interface OddFilterDto {
  market: string;
  minOdd?: number;
  maxOdd?: number;
}

export interface DateRangeDto {
  from: string;
  to: string;
}

export interface MatchQueryDto {
  sport: SportType;
  limit?: number;
  leagueId?: string;
  status?: MatchStatus;
  date?: string; // YYYY-MM-DD
  team?: TeamFilterDto;
  odds?: OddFilterDto[];
  dateRange?: DateRangeDto;
}

export interface MatchListParams {
  page?: number;
  limit?: number;
  sport?: SportType;
}

// ========================
// Response DTOs
// ========================

export interface MatchResponseDto {
  id: string;
  matchName: string;
  matchSlug?: string;
  mstUtc: number | string; // Timestamp
  date?: string | Date;
  status: MatchStatus;
  state?: string;

  // Scores
  scoreHome?: number;
  scoreAway?: number;
  score?: { home: number; away: number };
  htScoreHome?: number;
  htScoreAway?: number;

  // Teams
  homeTeamName: string;
  homeTeamLogo?: string;
  awayTeamName: string;
  awayTeamLogo?: string;

  // League & Country
  leagueName?: string;
  countryName?: string;

  // Odds (dynamic key-value)
  odds?: Record<string, Record<string, { odd: string }>>;

  // Nested Objects (from Backend include)
  homeTeam?: { name: string; logo?: string; [key: string]: unknown };
  awayTeam?: { name: string; logo?: string; [key: string]: unknown };
  league?: {
    name: string;
    country?: { name: string; flag?: string };
    [key: string]: unknown;
  };
  lineups?: {
    home: Array<{
      player?: { name: string; id: string; [key: string]: unknown };
      position?: string | null;
      shirtNumber?: number | null;
      isStarting?: boolean;
      [key: string]: unknown;
    }>;
    away: Array<{
      player?: { name: string; id: string; [key: string]: unknown };
      position?: string | null;
      shirtNumber?: number | null;
      isStarting?: boolean;
      [key: string]: unknown;
    }>;
  };

  [key: string]: unknown;
}

export interface ActiveLeagueDto {
  id: string;
  name: string;
  code?: string;
  countryName?: string;
  countryFlag?: string;
  matchCount: number;
  liveCount: number;
}

export interface LeagueWithMatchesDto {
  id: string;
  name: string;
  code?: string;
  country: {
    id: string;
    name: string;
    flagUrl?: string; // Backend uses flagUrl
  };
  sport: SportType;
  matches: MatchResponseDto[];
}
