import request from '@/utils/request'

export interface OverviewData {
  summary: {
    totalContests: number
    totalRegistrations: number
    passedRegistrations: number
    totalWorks: number
    reviewedWorks: number
    awardedWorks: number
  }
  funnel: {
    registered: number
    passed: number
    submitted: number
    reviewed: number
    awarded: number
  }
  monthlyTrend: Array<{ month: string; registrations: number; works: number }>
  contestComparison: Array<{
    contestId: number
    contestName: string
    registrations: number
    passRate: number
    submitRate: number
    reviewRate: number
    awardRate: number
    avgScore: number | null
  }>
}

export interface ReviewData {
  efficiency: {
    avgReviewDays: number
    dailyReviewCount: number
    pendingAssignments: number
    avgScoreStddev: number
  }
  judgeWorkload: Array<{
    judgeId: number
    judgeName: string
    contestCount: number
    assignedCount: number
    scoredCount: number
    completionRate: number
    avgScore: number | null
    scoreStddev: number
  }>
  awardDistribution: Array<{
    awardName: string
    count: number
    percentage: number
  }>
}

export const analyticsApi = {
  getOverview: (params?: { timeRange?: string; contestId?: number }): Promise<OverviewData> =>
    request.get('/analytics/overview', { params }),

  getReview: (params?: { contestId?: number }): Promise<ReviewData> =>
    request.get('/analytics/review', { params }),
}
