// 监考模块类型定义

export type ProctoringEventType =
  | "tab_switch"
  | "window_blur"
  | "copy_attempt"
  | "paste_attempt"
  | "right_click"
  | "devtools_open"
  | "fullscreen_exit"
  | "idle_timeout"

export type ExamMode = "homework" | "timed" | "proctored"

export type SubmissionStatus = "started" | "submitted" | "graded"

/**
 * 监考事件（原始记录）
 */
export interface ProctoringEvent {
  id: string
  submissionId: string
  studentId: string
  examId: string
  eventType: ProctoringEventType
  eventDetail?: string | null
  occurredAt: string
  createdAt: string
}

/**
 * 监考事件（含学生姓名、考试标题等关联信息）
 */
export interface ProctoringEventWithDetails extends ProctoringEvent {
  studentName: string
  examTitle: string
}

/**
 * 监考事件输入参数
 */
export interface RecordProctoringEventInput {
  submissionId: string
  studentId: string
  examId: string
  eventType: ProctoringEventType
  eventDetail?: string
}

/**
 * 监考事件查询过滤条件
 */
export interface GetProctoringEventsFilters {
  studentId?: string
  eventType?: ProctoringEventType
  startedAt?: string
  endedAt?: string
}

/**
 * 考试监考摘要
 */
export interface ExamProctoringSummary {
  examId: string
  examTitle: string
  examMode: ExamMode
  totalStudents: number
  startedStudents: number
  submittedStudents: number
  totalEvents: number
  abnormalStudents: number
  eventsByType: Record<ProctoringEventType, number>
}

/**
 * 学生监考状态
 */
export interface StudentProctoringStatus {
  studentId: string
  studentName: string
  submissionId: string | null
  submissionStatus: SubmissionStatus | null
  eventCount: number
  lastEventAt: string | null
  isAbnormal: boolean
  eventsByType: Record<ProctoringEventType, number>
}

/**
 * 监考面板数据（合并摘要与学生状态）
 */
export interface ProctoringDashboardData {
  summary: ExamProctoringSummary
  students: StudentProctoringStatus[]
  recentEvents: ProctoringEventWithDetails[]
}

/**
 * 考试模式配置（用于考试创建/编辑表单）
 */
export interface ExamModeConfig {
  examMode: ExamMode
  durationMinutes: number | null
  shuffleQuestions: boolean
  allowLateStart: boolean
  lateStartGraceMinutes: number
  antiCheatEnabled: boolean
}

/**
 * 监考事件类型显示标签
 */
export const PROCTORING_EVENT_LABELS: Record<ProctoringEventType, string> = {
  tab_switch: "切换标签页",
  window_blur: "窗口失焦",
  copy_attempt: "复制操作",
  paste_attempt: "粘贴操作",
  right_click: "右键点击",
  devtools_open: "开发者工具",
  fullscreen_exit: "退出全屏",
  idle_timeout: "空闲超时",
}

/**
 * 考试模式显示标签
 */
export const EXAM_MODE_LABELS: Record<ExamMode, string> = {
  homework: "作业模式",
  timed: "限时模式",
  proctored: "监考模式",
}

/**
 * 异常事件阈值：超过该值视为异常学生
 */
export const ABNORMAL_EVENT_THRESHOLD = 3
