import { z } from "zod"

// ============ Teacher Class Schemas ============

/** 教师创建班级 */
export const CreateTeacherClassSchema = z.object({
  name: z.string().trim().min(1),
  grade: z.string().trim().min(1),
  schoolName: z.string().nullable().optional(),
  schoolId: z.string().nullable().optional(),
  gradeId: z.string().nullable().optional(),
  homeroom: z.string().nullable().optional(),
  room: z.string().nullable().optional(),
})

export type CreateTeacherClassInput = z.infer<typeof CreateTeacherClassSchema>

/** 教师更新班级 */
export const UpdateTeacherClassSchema = z.object({
  classId: z.string().trim().min(1),
  schoolName: z.string().nullable().optional(),
  schoolId: z.string().nullable().optional(),
  name: z.string().nullable().optional(),
  grade: z.string().nullable().optional(),
  gradeId: z.string().nullable().optional(),
  homeroom: z.string().nullable().optional(),
  room: z.string().nullable().optional(),
})

export type UpdateTeacherClassInput = z.infer<typeof UpdateTeacherClassSchema>

/** 教师删除班级 */
export const DeleteTeacherClassSchema = z.object({
  classId: z.string().trim().min(1),
})

export type DeleteTeacherClassInput = z.infer<typeof DeleteTeacherClassSchema>

// ============ Admin Class Schemas ============

/** 管理员创建班级 */
export const CreateAdminClassSchema = z.object({
  name: z.string().trim().min(1),
  grade: z.string().trim().min(1),
  teacherId: z.string().trim().min(1),
  schoolName: z.string().nullable().optional(),
  schoolId: z.string().nullable().optional(),
  gradeId: z.string().nullable().optional(),
  homeroom: z.string().nullable().optional(),
  room: z.string().nullable().optional(),
})

export type CreateAdminClassInput = z.infer<typeof CreateAdminClassSchema>

/** 管理员更新班级 */
export const UpdateAdminClassSchema = z.object({
  classId: z.string().trim().min(1),
  schoolName: z.string().nullable().optional(),
  schoolId: z.string().nullable().optional(),
  name: z.string().nullable().optional(),
  grade: z.string().nullable().optional(),
  gradeId: z.string().nullable().optional(),
  teacherId: z.string().nullable().optional(),
  homeroom: z.string().nullable().optional(),
  room: z.string().nullable().optional(),
})

export type UpdateAdminClassInput = z.infer<typeof UpdateAdminClassSchema>

/** 管理员删除班级 */
export const DeleteAdminClassSchema = z.object({
  classId: z.string().trim().min(1),
})

export type DeleteAdminClassInput = z.infer<typeof DeleteAdminClassSchema>

// ============ Grade Class Schemas ============

/** 年级主任创建班级 */
export const CreateGradeClassSchema = z.object({
  name: z.string().trim().min(1),
  gradeId: z.string().trim().min(1),
  teacherId: z.string().trim().min(1),
  schoolName: z.string().nullable().optional(),
  schoolId: z.string().nullable().optional(),
  grade: z.string().nullable().optional(),
  homeroom: z.string().nullable().optional(),
  room: z.string().nullable().optional(),
})

export type CreateGradeClassInput = z.infer<typeof CreateGradeClassSchema>

/** 年级主任更新班级 */
export const UpdateGradeClassSchema = z.object({
  classId: z.string().trim().min(1),
  schoolName: z.string().nullable().optional(),
  schoolId: z.string().nullable().optional(),
  name: z.string().nullable().optional(),
  grade: z.string().nullable().optional(),
  gradeId: z.string().nullable().optional(),
  teacherId: z.string().nullable().optional(),
  homeroom: z.string().nullable().optional(),
  room: z.string().nullable().optional(),
})

export type UpdateGradeClassInput = z.infer<typeof UpdateGradeClassSchema>

/** 年级主任删除班级 */
export const DeleteGradeClassSchema = z.object({
  classId: z.string().trim().min(1),
})

export type DeleteGradeClassInput = z.infer<typeof DeleteGradeClassSchema>

// ============ Class Schedule Item Schemas ============

/** 创建课表项 */
export const CreateClassScheduleItemSchema = z.object({
  classId: z.string().trim().min(1),
  weekday: z.coerce.number().int().min(1).max(7),
  course: z.string().trim().min(1),
  startTime: z.string().min(1),
  endTime: z.string().min(1),
  location: z.string().nullable().optional(),
})

export type CreateClassScheduleItemInput = z.infer<typeof CreateClassScheduleItemSchema>

/** 更新课表项 */
export const UpdateClassScheduleItemSchema = z.object({
  scheduleId: z.string().trim().min(1),
  classId: z.string().nullable().optional(),
  weekday: z.coerce.number().int().min(1).max(7).nullable().optional(),
  course: z.string().nullable().optional(),
  startTime: z.string().nullable().optional(),
  endTime: z.string().nullable().optional(),
  location: z.string().nullable().optional(),
})

export type UpdateClassScheduleItemInput = z.infer<typeof UpdateClassScheduleItemSchema>

/** 删除课表项 */
export const DeleteClassScheduleItemSchema = z.object({
  scheduleId: z.string().trim().min(1),
})

export type DeleteClassScheduleItemInput = z.infer<typeof DeleteClassScheduleItemSchema>

// ============ Enrollment Schemas ============

/** 通过邮箱注册学生 */
export const EnrollStudentByEmailSchema = z.object({
  classId: z.string().trim().min(1),
  email: z.string().trim().min(1),
})

export type EnrollStudentByEmailInput = z.infer<typeof EnrollStudentByEmailSchema>
