import type { PaginationDto } from "@/types/api-response";

// ========================
// Shared Query Params
// ========================

export interface AdminPaginationParams extends PaginationDto {
  sortBy?: string;
  sortOrder?: "asc" | "desc";
  search?: string;
  role?: string;
  subscriptionStatus?: string;
}

// ========================
// Settings
// ========================

export interface SettingDto {
  key: string;
  value: string;
}

export interface UpdateSettingDto {
  value: string;
}

// ========================
// Usage Limits
// ========================

export interface UsageLimitDto {
  id: string;
  userId: string;
  feature: string;
  used: number;
  limit: number;
  resetAt?: string;
  [key: string]: unknown;
}

// ========================
// Admin Users
// ========================

export interface AdminUserDto {
  id: string;
  email: string;
  firstName?: string;
  lastName?: string;
  role?: string;
  isActive: boolean;
  subscription?: string;
  subscriptionStatus?: string;
  subscriptionExpiresAt?: string | null;
  createdAt: string;
  [key: string]: unknown;
}

export interface UpdateUserRoleDto {
  role: string;
}

export interface UpdateUserSubscriptionDto {
  plan: string;
  expiresAt?: string | null;
}

// ========================
// League Tiers
// ========================

export interface LeagueTierDto {
  id: number;
  leagueId: string;
  tier: number;
  isActive: boolean;
  addedBy?: string;
  notes?: string;
  createdAt: string;
  updatedAt: string;
  league: {
    id: string;
    name: string;
    country?: {
      id: string;
      name: string;
      code?: string;
    };
  };
}

export interface LeagueTierStatsDto {
  tiers: { tier: number; count: number }[];
  totalActiveLeagues: number;
  totalQualifiedMatches: number;
}

export interface AddLeagueTierDto {
  leagueId: string;
  tier?: number;
  notes?: string;
  addedBy?: string;
}

export interface UpdateLeagueTierDto {
  tier: number;
}

export interface RetrainStatusDto {
  running: boolean;
  last_started?: string;
  last_completed?: string;
  last_status?: string;
  last_error?: string;
}

// ========================
// Analytics
// ========================

export interface AnalyticsOverviewDto {
  totalUsers?: number;
  activeUsers?: number;
  totalPredictions?: number;
  totalCoupons?: number;
  users?: {
    total: number;
    active: number;
    premium: number;
  };
  matches?: number;
  predictions?: number;
  aiHealth?: Record<string, unknown>;
  [key: string]: unknown;
}

// ========================
// Model Performance (Forward-Test)
// ========================

export interface ModelPerformanceMarketDto {
  market: string;
  samples: number;
  shown_pct: number;
  actual_pct: number;
  gap: number;
  ece: number;
  calibration: "good" | "overconfident" | "underconfident";
  bet_count: number;
  bet_hit_pct: number;
  bet_roi_pct: number;
  actions: Record<string, number>;
  tiers: Record<string, number>;
}

export interface ModelPerformanceDto {
  window_days: number;
  settled_runs: number;
  settled_markets: number;
  generated_at: string;
  markets: ModelPerformanceMarketDto[];
}
