import { get } from '#/api/http'

export interface ClassItem {
  id: string
  name: string
  gradeId: string
  gradeName: string
  schoolId: string
}

export interface SubjectItem {
  id: string
  name: string
}

export interface SubjectStat {
  subjectId: number
  subjectName: string
  homeworkCount: number
  completedCount: number
  uncompletedCount: number
}

export interface StudentHomework {
  userId: number
  userName: string
  totalCount: number
  completedCount: number
  uncompletedCount: number
  subjectStats: SubjectStat[]
}

export interface ClassHomeworkResult {
  classId: number
  className: string
  subjects: SubjectItem[]
  studentList: StudentHomework[]
}

export interface ClassHomeworkParams {
  classId: string
  startTime?: string
  endTime?: string
  subjectIds?: string[]
}

export async function getClassListByTeacher(): Promise<ClassItem[]> {
  const res = await get<any>('/org/class/listByTeacher')
  return Array.isArray(res) ? res : (res?.rows ?? res?.data ?? [])
}

export async function getSubjectsByClassId(
  classId: string,
): Promise<SubjectItem[]> {
  const res = await get<any>('/org/class/listSubjectInfoByClassId', {
    classId,
  })
  return Array.isArray(res) ? res : (res?.data ?? [])
}

export async function getClassHomeworkList(
  params: ClassHomeworkParams,
): Promise<ClassHomeworkResult> {
  const res = await get<any>('/school/report/classHomework/list', params)
  return res ?? {}
}
