/**
 * 团队看板API
 */

import request from './request'

export interface TeamOverview {
  team_count: number
  member_count: number
  avg_progress: number
  avg_score: number
  course_completion_rate: number
  trends: {
    member_trend: number
    progress_trend: number
    score_trend: number
    completion_trend: number
  }
}

export interface ProgressData {
  members: string[]
  weeks: string[]
  data: Array<{
    name: string
    values: number[]
  }>
}

export interface CourseDistribution {
  completed: number
  in_progress: number
  not_started: number
}

export interface AbilityAnalysis {
  radar_data: {
    dimensions: string[]
    values: number[]
  }
  weaknesses: Array<{
    name: string
    avg_score: number
    suggestion: string
  }>
}

export interface RankingMember {
  id: number
  name: string
  position: string
  avatar: string
  study_time?: number
  avg_score?: number
}

export interface Rankings {
  study_time_ranking: RankingMember[]
  score_ranking: RankingMember[]
}

export interface Activity {
  id: number | string
  user_name: string
  action: string
  target: string
  time: string
  type: string
  result?: { type: string; text: string }
}

export interface ActivitiesResponse {
  activities: Activity[]
}

/**
 * 获取团队概览统计
 */
export const getTeamOverview = () => {
  return request.get<TeamOverview>('/api/v1/team/dashboard/overview')
}

/**
 * 获取学习进度数据
 */
export const getProgressData = () => {
  return request.get<ProgressData>('/api/v1/team/dashboard/progress')
}

/**
 * 获取课程完成分布
 */
export const getCourseDistribution = () => {
  return request.get<CourseDistribution>('/api/v1/team/dashboard/course-distribution')
}

/**
 * 获取能力分析数据
 */
export const getAbilityAnalysis = () => {
  return request.get<AbilityAnalysis>('/api/v1/team/dashboard/ability-analysis')
}

/**
 * 获取排行榜数据
 */
export const getRankings = () => {
  return request.get<Rankings>('/api/v1/team/dashboard/rankings')
}

/**
 * 获取团队动态
 */
export const getActivities = () => {
  return request.get<ActivitiesResponse>('/api/v1/team/dashboard/activities')
}

