import { EnumPaperBuildType, EnumPaperWorkState, EnumReviewMode, EnumSimulatedRecordStatus } from "@/common/enum";

export interface TeachClass {
  classId: number;
  schoolId: number;
  year: number;
  name: string;
}

export interface StudentStat {
  id: number;
  avatar?: string;
  name: string;
  questionNum: number;
  dateNum: number;
  rate: number;
}

/**
 * 班级知识点记录
 */
export interface ClassKnowledgeRecord {
  rate: number;
  list: StudentPlanStudyRecord[];
}

/**
 * 班级学生刷题记录
 */
export interface StudentPlanStudyRecord {
  id: number;
  avatar?: string;
  name: string;
  rate: number;
  time: number;
  total: number;
  value: number;
}

export interface StudentPracticeRecord {
  id: number;
  avatar?: string;
  name: string;
  rate: number;
  time: number;
  total: number;
  value: number;
}

export interface StudentExamRecord {
  id: number;
  name: string;
  total: number;
  value: number;
  rate: number;
}

/**
 * 组卷批次信息
 */
export interface Batch {
  batchId: number;
  name: string;
  year: number;
}

/**
 * 班级学生视频学习记录
 */
export interface StudentVideoRecord {
  id: number;
  name: string;
  total: string;
  value: number;
  seq: number;
}

export interface PaperWorkRecord {
  buildStatus: number | null;
  count: number | null;
}

export interface PaperWorkRecordQuery {
  buildStatus: number | null;
  batchId: number | null;
  buildType: EnumPaperBuildType;
  classId: number | null;
  subjectId: number | null;
}

export interface PaperWorkRecordDetail {
  className: string;
  nickName: string;
  state: string;
  studentId: number;
}

/**
 * 学习计划
 */
export interface StudyPlan {
  id?: number;
  beginTime?: string;
  questionCnt: number;
  studentId?: number;
  videoTime: number;
  status?: number;
}

/**
 * 学习计划统计数据
 */
export interface StudyStats {
  questionCnt: number; // 答题数
  videoTime: number; // 课程学习数量
  videoTimes: number; // 学习时长
  rightRate: number; // 正确率
  questionPlan: number; // 计划答题数
  videoPlan: number; // 计划课程学习时长
}
export interface StudyStatsHistory {
  date: string; // 日期 2025-10-12
  data: StudyStats; // 数据
}
export interface StudyPlanStats {
  doneDay: number; // 本月完成
  undoneDay: number; // 本月未完成
  videoTimes: number; // 本月课程学习时长
  questionCnt: number; // 本月答题数
  studyList: StudyStatsHistory[]; // 历史数据（包含今天）
  today: StudyStats,
  plan: StudyPlan
}

export interface Subject {
  subjectId: number;
  subjectName: string;
}

export interface Knowledge {
  id: number;
  name: string;
  status: number;
  questionCount: number;
  children: Knowledge[];
  finishedCount: number;
  finishedRatio: number;
}

export type KnowledgeNode = Pick<Knowledge, 'id' | 'name' | 'status' | 'questionCount' | 'finishedCount' | 'finishedRatio'> & {
  isExpanded: boolean;
  isLeaf: boolean;
  children: KnowledgeNode[];
}

export interface QuestionState {
  isDone?: boolean;
  isMark?: boolean;
  isNotKnow?: boolean;
  isNotAnswer?: boolean;
  isFavorite?: boolean;
  isCorrect?: boolean;
  isLeaf?: boolean; // 是否是叶子节点
  progress?: number;
  //
  showParse?: boolean; // 是否显示解析
  hasParsed?: boolean; // 是否已经解析过，用于背题模式
}

/**
 * 开卷信息，包含上次做题历史数据
 */
export interface ExamineeQuestion {
  id: number;
  typeId: number;
  answer1: string;
  answer2: string;
  score: number;
  title?: string;
  options?: string[];
  isFavorite: boolean;
  isMark: boolean;
  isNotKnow: boolean;
  answers: string[];
  subQuestions: ExamineeQuestion[];
  parse?: string;
  totalScore: number;
  // 原始题型名称
  typeTitle?: string;
}
export interface Examinee {
  examineeId: number;
  name: string;
  paperId: number;
  duration: number;
  knowledgeId: number;
  questions: ExamineeQuestion[];
  // 
  paperInfo: ExamineePaperInfo;
  collegeName: string;
  majorName: string;
  collegeId: number;
  majorId: number;
  subjectName: string;
  subjectId: number;
  totalCount: number;
  wrongCount: number;
  stats: ExamineeStats;
}
export interface ExamineePaperInfo {
  score: number;
  time: number;
  types: {
    type: string;
    count: number;
    score: number;
  }[]
}
export interface ExamineeStats {
  averageScore: number;
  hitRate: number;
  maxScore: number;
  rate: number;
  score: number;
}

/**
 * 试卷
 */
export interface ExamPaper {
  id: number;
  paperName: string;
  paperType: string;
  questions: ExamineeQuestion[];
  score?: number;
  subjectId: number;
  year: number;
}

export type ExamPaperQuestion = Pick<ExamineeQuestion, 'id' | 'title' | 'options' | 'subQuestions'>;

export interface ExamPaperSubmit {
  id: number;
  paperName: string;
  paperType: string;
  questions: Question[];
  score?: number;
  subjectId: number;
  year: number;
  duration?: number;
  examineeId?: number;
  isDone?: boolean;
}

export interface QuestionOptionState {
  isAnswer: boolean;
  isCorrect: boolean;
  isSelected: boolean;
  isMissed: boolean;
  isIncorrect: boolean;
}

export interface PracticeSettings {
  reviewMode: EnumReviewMode;
  autoNext: boolean;
}

export interface QuestionOption extends QuestionOptionState {
  id: number;
  no: string; // A, B, C, D
  name: string;
}

export interface Question extends QuestionState {
  id: number;
  title: string;
  typeId: number;
  options: QuestionOption[];
  answers: string[];
  answer1: string;
  answer2: string;
  parse?: string;
  subQuestions: Question[];
  totalScore: number;
  //
  index: number; // 当前题目在原始数组中的索引，如果是子题，则index和父题的 index 一致
  offset: number; // 前面所有子题数量的偏移量
  isSubQuestion?: boolean; // 是否是子题
  //
  parentIndex?: number; // 子题中父题在原始数组中的索引
  parentId?: number; // 父题ID
  parentTypeId?: number; // 父题类型
  subIndex?: number; // 子题在父题中的索引
  //
  virtualIndex: number; // 在平铺数组中的虚拟索引
  activeSubIndex: number; // 父题中正在展示的子题索引
  // 单题做题时间
  duration: number;
  // 是否有子题
  hasSubQuestions: boolean;
  // 原始题型名称
  typeTitle?: string;
}

export interface SubjectListRequestDTO {
  directed?: boolean;
  questionType?: number;
  subjectType?: number;
}

export interface KnowledgeListRequestDTO {
  subjectId: number;
  directed: boolean;
}

export interface OpenExamineeRequestDTO {
  paperType: string,
  relateId?: number,
  directed?: boolean,
  subjectId?: number,
  testType?: string;
  questionType?: number;
}

export interface GetExamPaperRequestDTO {
  type: string,
  id: number
}

export interface DirectedSchool extends SelectedUniversityMajor {
  code: string;
  notice: string;
}

export interface University {
  code: string;
  id: number;
  name: string;
  logo: string;
  type: string;
}

export interface UniversityMajor {
  ancestors: string;
  code: string;
  id: number;
  name: string;
  type: string;
  notice?: string;
}

// 

export interface SelectedUniversityMajor {
  universityLogo: string;
  universityId: string;
  universityName: string;
  majorId: string; // 计划ID，可确保唯一性
  majorName: string;
  majorAncestors: string;
  majorGroup: string;
}

export interface SimulationTestOptions {
  universityId: string;
  universityName: string;
  majorId: string;
  majorName: string;
}

export interface SimulationTestInfo {
  evalCount: number;
  subjects: string[]
}


// 学习记录
export interface KnowledgeRecord {
  name: string;
  total: number;
  rate: number;
  directed: boolean; // 是否是定向
}

export interface SimulatedRecord {
  id: number;
  rate: number;
  name: string;
  score: number;
  total: number;
  date: string;
  // 
  subjectName: string;
  state: EnumSimulatedRecordStatus;
  //
  subjectGroup: string;
}

/**
 * 视频学习统计
 */
export interface VideoStudy {
  study: number;
  total: number;
  list: VideoStudyRecord[]
}

/**
 * 视频学习记录
 */
export interface VideoStudyRecord {
  name: string;
  date: string;
  study: string;
}

export interface PracticeRecord {
  rate: number;
  total: number;
  studyDays: number;
  list: {
    rate: number;
    date: string;
    study: number;
  }[]
}

/**
 * 模拟考试科目
 */
export interface SimulationExamSubject {
  subjectId: number;
  subject: string;
  examTime: number;
  icon: string;
}

export interface PracticeHistory {
  directed: number;
  endTime: string;
  examineeId: number;
  paperName: string;
  questionType?: number;
}

/**
 * 组卷作业
 */
export interface PaperWork {
  id: number;
  name: string;
  subjectId: number;
  total: number;
  state: EnumPaperWorkState;
  subjectName: string;
  date: string;
  campusName: string;
  directed: boolean;
  majorName: string;
  publishUser: string;
  publishTime: string;
  schoolName: string;
  score: number;
  universityName: string;
  endTime: string;
  duration: number;
  batchName: string;
}

export interface VHSPaperListRequestDTO {
  subjectId: number;
}

export interface VHSPaper {
  collect: boolean;
  createBy: string | null;
  createTime: string;
  directKey: string;
  examineeId: string | null;
  examineeTypes: string;
  fenshu: number;
  filename: string;
  id: number;
  locations: string;
  number: string | null;
  ospath: string | null;
  paperInfo: string | null;
  paperName: string;
  paperSource: number;
  paperType: string;
  relateId: number;
  remark: string | null;
  status: number;
  subjectId: number;
  subjectName: string;
  tiid: string;
  updateBy: string | null;
  updateTime: string | null;
  year: string | null;
}


/**
 * 收藏题目列表请求参数
 */
export interface FavoriteQuestionListRequestDTO {
  pageNum: number;
  pageSize: number;
  type: string;
  subjectId: number;
}
/**
 * 收藏题目
 */
export interface FavoriteQuestion {
  answer0: string | null;
  answer1: string | null;
  answer2: string | null;
  area: string | null;
  collect: boolean;
  createBy: string | null;
  createTime: string;
  diff: number;
  fromSite: string;
  gradeId: number;
  id: number;
  isKonw: boolean | null;
  isNormal: boolean | null;
  isSub: boolean | null;
  isSubType: string;
  isUpdate: number;
  isunique: boolean | null;
  knowId: number | null;
  knowledgeId: number;
  knowledges: any | null;
  md5: string | null;
  md52: string | null;
  number: string | null;
  optionA: string;
  optionB: string;
  optionC: string;
  optionD: string;
  optionE: string | null;
  optionF: string | null;
  optionG: string | null;
  options: any | null;
  options0: any | null;
  paperId: number | null;
  paperTpye: string | null;
  paperTypeTitle: string | null;
  parse: string;
  parse0: string | null;
  qtpye: string;
  remark: string | null;
  score: number;
  similarity: number;
  source: string;
  subCnt: number | null;
  subjectId: number;
  tiid: string;
  title: string;
  title0: string;
  title1: string | null;
  typeId: number;
  updateBy: string | null;
  updateTime: string | null;
  userId: number | null;
  year: number;
}

/**
 * 收藏题目VO
 */
export interface FavoriteQuestionVO {
  id: number;
  title: string;
  options: QuestionOption[];
  answers: string[];
  answer: string;
  parse: string;
  qtype: string;
  typeId: number;
  knowledge?: string;
  collect: boolean;
}

/**
 * 学生科目
 */
export interface StudentSubject {
  createBy: string | null;
  createTime: string | null;
  updateBy: string | null;
  updateTime: string | null;
  remark: string | null;
  subjectId: number;
  subjectName: string;
  pinyin: string | null;
  sort: number;
  locations: string;
  examTypes: string;
  groupName: string;
}


export interface WrongBookQuestionRequestDTO {
  pageNum: number;
  pageSize: number;
  subjectId: number;
  start?: string;
  end?: string;
}

/**
 * 错题本题目
 */
export interface WrongBookQuestion {
  createBy: string | null;
  createTime: string | null;
  updateBy: string | null;
  updateTime: string | null;
  remark: string | null;
  wrongId: number;
  studentId: number | null;
  questionId: number;
  source: string | null;
  state: number;
  knownledgeId: number;
  subjectId: number | null;
  paperId: number | null;
  answer: string;
  answer1: string;
  answer2: string;
  scoreTotal: number | null;
  score: number | null;
  scoreLevel: string | null;
  scoreRate: number | null;
  wrongCount: number;
  rightCount: number | null;
  totalCount: number | null;
  createdTime: string | null;
  updatedTime: string | null;
  collect: boolean | null;
  knownledgeName: string | null;
  title: string;
  knowledge: string;
  parse: string;
  typeId: number;
  type: string;
  options: string[];
  answers: string[];
}

/**
 * 视频课程科目请求参数
 */
export interface VideoCourseSubjectRequestDTO {
  pageNum: number;
  pageSize: number;
  type: number;
}
/**
 * 视频课程科目
 */
export interface VideoCourseSubject {
  code: number;
  label: string;
}
/**
 * 视频课程知识点
 */
export interface VideoCourseKnowledge {
  code: number;
  label: string;
  children: VideoCourse[];
}
/**
 * 视频课程请求参数
 */
export interface VideoCourseRequestDTO {
  pageNum: number;
  pageSize: number;
  subject: number;
  knowledge: number;
}
/**
 * 视频课程
 */
export interface VideoCourse {
  aliId: string;
  aliIdType: number;
  img: string;
  name: string;
}
/**
 * 视频课程播放信息
 */
export interface VideoCoursePlayInfo {
  coverUrl: string;
  duration: string;
  palyUrl: string;
  title: string;
  videoId: string;
}

/**
 * 视频课程学习记录
 */
export interface VideoCourseRecordDTO {
  sectionId: string;
  duration: number;
  percent: string;
  type: number;
}