// Scheduling module type definitions

export type ScheduleChangeStatus = "pending" | "approved" | "rejected" | "completed"

export type Weekday = 1 | 2 | 3 | 4 | 5 | 6 | 7

export type CreateClassScheduleItemInput = {
  classId: string
  weekday: Weekday
  startTime: string
  endTime: string
  course: string
  location?: string | null
}

export type UpdateClassScheduleItemInput = {
  classId?: string
  weekday?: Weekday
  startTime?: string
  endTime?: string
  course?: string
  location?: string | null
}

export interface SchedulingRule {
  id: string
  classId: string | null
  maxDailyHours: number
  maxContinuousHours: number
  lunchBreakStart: string
  lunchBreakEnd: string
  morningStart: string
  afternoonEnd: string
  avoidBackToBack: boolean
  balancedSubjects: boolean
  createdAt: string
  updatedAt: string
}

export interface ScheduleChange {
  id: string
  originalScheduleId: string | null
  classId: string
  originalTeacherId: string | null
  substituteTeacherId: string | null
  originalDate: string | null
  newDate: string | null
  newStartTime: string | null
  newEndTime: string | null
  reason: string | null
  status: ScheduleChangeStatus
  requestedBy: string
  approvedBy: string | null
  createdAt: string
  updatedAt: string
}

export interface ScheduleChangeListItem extends ScheduleChange {
  className: string
  originalTeacherName: string | null
  substituteTeacherName: string | null
  requesterName: string
  approverName: string | null
}

export interface TimeSlot {
  weekday: number
  startTime: string
  endTime: string
}

export interface ScheduleConflict {
  type: "teacher_overlap" | "classroom_overlap" | "class_overlap" | "rule_violation"
  description: string
  scheduleIds: string[]
}

export interface AutoScheduleResult {
  success: boolean
  scheduledCount: number
  conflictCount: number
  conflicts: ScheduleConflict[]
  schedules: GeneratedSchedule[]
}

export interface GeneratedSchedule {
  classId: string
  weekday: number
  startTime: string
  endTime: string
  course: string
  location: string | null
  teacherId: string | null
  subjectId: string | null
}

export interface AutoScheduleSubject {
  subjectId: string
  subjectName: string
  weeklyHours: number
  teacherId: string | null
}

export interface AutoScheduleTeacher {
  id: string
  name: string
}

export interface AutoScheduleClassroom {
  id: string
  name: string
}

export interface AutoScheduleParams {
  classId: string
  rules: SchedulingRule
  subjects: AutoScheduleSubject[]
  teachers: AutoScheduleTeacher[]
  classrooms: AutoScheduleClassroom[]
  timeSlots: TimeSlot[]
}

export interface ScheduleChangeQueryParams {
  classId?: string
  status?: ScheduleChangeStatus
  requesterId?: string
}

export const SCHEDULE_CHANGE_STATUS_LABELS: Record<ScheduleChangeStatus, string> = {
  pending: "Pending",
  approved: "Approved",
  rejected: "Rejected",
  completed: "Completed",
}

export const SCHEDULE_CHANGE_STATUS_COLORS: Record<
  ScheduleChangeStatus,
  "default" | "secondary" | "destructive" | "outline"
> = {
  pending: "secondary",
  approved: "default",
  rejected: "destructive",
  completed: "outline",
}
