import { z } from "zod"

export const AttendanceStatusEnum = z.enum([
  "present",
  "absent",
  "late",
  "early_leave",
  "excused",
])

export const RecordAttendanceSchema = z.object({
  studentId: z.string().min(1),
  classId: z.string().min(1),
  date: z.string().min(1),
  status: AttendanceStatusEnum,
  remark: z.string().optional(),
  scheduleId: z.string().optional(),
})

export type RecordAttendanceInput = z.infer<typeof RecordAttendanceSchema>

export const BatchRecordAttendanceSchema = z.object({
  records: z.array(RecordAttendanceSchema),
})

export type BatchRecordAttendanceInput = z.infer<typeof BatchRecordAttendanceSchema>

export const UpdateAttendanceSchema = z.object({
  status: AttendanceStatusEnum.optional(),
  remark: z.string().optional(),
  scheduleId: z.string().optional(),
})

export type UpdateAttendanceInput = z.infer<typeof UpdateAttendanceSchema>

export const AttendanceRuleSchema = z.object({
  classId: z.string().min(1),
  lateThresholdMinutes: z.coerce.number().int().min(0).optional(),
  earlyLeaveThresholdMinutes: z.coerce.number().int().min(0).optional(),
  enableAutoMark: z.coerce.boolean().optional(),
})

export type AttendanceRuleInput = z.infer<typeof AttendanceRuleSchema>
