import "server-only"

import { getStudentClasses, getStudentSchedule } from "@/modules/classes/data-access"
import { getStudentHomeworkAssignments } from "@/modules/homework/data-access-student"
import { getStudentDashboardGrades } from "@/modules/homework/stats-service"
import { getTeacherClasses, getTeacherTeachingSubjects } from "@/modules/classes/data-access"

/**
 * Profile 概览数据访问层
 *
 * 将 classes/homework 模块的 data-access 调用封装在 settings 模块内部，
 * 避免 settings 组件层直接 import 其他业务模块的 data-access。
 * 模块间通过 data-access 通信是允许的，组件层直接 import 则违反解耦原则。
 */

/**
 * 获取学生概览所需的所有数据（并行查询）
 */
export async function getStudentProfileOverviewData(userId: string): Promise<{
  classes: Awaited<ReturnType<typeof getStudentClasses>>
  schedule: Awaited<ReturnType<typeof getStudentSchedule>>
  assignments: Awaited<ReturnType<typeof getStudentHomeworkAssignments>>
  grades: Awaited<ReturnType<typeof getStudentDashboardGrades>>
}> {
  const [classes, schedule, assignments, grades] = await Promise.all([
    getStudentClasses(userId),
    getStudentSchedule(userId),
    getStudentHomeworkAssignments(userId),
    getStudentDashboardGrades(userId),
  ])
  return { classes, schedule, assignments, grades }
}

/**
 * 获取教师概览所需的所有数据（并行查询）
 */
export async function getTeacherProfileOverviewData(): Promise<{
  subjects: Awaited<ReturnType<typeof getTeacherTeachingSubjects>>
  classes: Awaited<ReturnType<typeof getTeacherClasses>>
}> {
  const [subjects, classes] = await Promise.all([
    getTeacherTeachingSubjects(),
    getTeacherClasses(),
  ])
  return { subjects, classes }
}
