import { PageResult, PageParams } from './common';

export interface SemesterItem {
  id: string;
  name: string;
}
export interface ExamItem {
  id: string;
  name: string;
}
export interface CourseItem {
  id: string;
  name: string;
  code: string;
}

export interface CourseQueryParams {
  semesterId: string;
  examId: string;
}
export interface PaperNumberQueryParams {
  semesterId: string;
  examId: string;
  courseId: string;
}

export interface CardData {
  id: string;
  content: string;
}

// task --------->
interface SplitConfig {
  /** index of sheets */
  i: number;
  /** 覆盖区域的width */
  w: number;
  /** 覆盖区域的height */
  h: number;
  /** 从哪里开始覆盖 左上角为 (0, 0) */
  x: number;
  /** 从哪里开始覆盖 左上角为 (0, 0) */
  y: number;
}

export interface Track {
  /** 大题号 */
  mainNumber: number;
  /** 小题号，当前api中只有number // 特殊标记中没有 */
  subNumber: string;
  /** 前端使用，暂时用不着，赋0 */
  number: number;
  /** 第几张图 */
  offsetIndex: number;
  /** 左上角为原点 */
  offsetX: number;
  offsetY: number;
  /** 相对slice的位置比例 */
  positionX: number;
  positionY: number;
  /** 评分数 */
  score: number;
  /** 是否此处未作答，未作答时，score默认是-0分 */
  unanswered: boolean;
  userId: string;
  userName: string;
  // 是否是科组长评卷轨迹
  headerMarkScore?: boolean;
  color?: string;
  isByMultMark?: boolean;
}

export interface Question {
  /** 分组序号 */
  groupNumber: number;
  /** 大题号 */
  mainNumber: number;
  /** 小题号 */
  subNumber: string;
  /** 分数间隔 */
  intervalScore: number;
  /** 默认分数 */
  defaultScore: number;
  /** 限制最小分数 */
  minScore: number;
  /** 限制最大分数 */
  maxScore: number;
  /** 题目名称 */
  title: string;
  /** 轨迹列表 */
  trackList: Array<Track>;
  /** 得分；null的值时是为打回时可以被评卷修改的；null也是从未评分过的情况，要通过rejected来判断 */
  score: number | null;
  /** 未计分 */
  uncalculate: boolean;
  /** 选做题分组 */
  selectiveIndex: number | null;
  /** 无轨迹情况下评卷员打分信息 */
  markerList: null | Array<{
    // 是否是科组长
    header: boolean;
    loginName: string;
    score: number;
    userId: string;
    userName: string;
  }>;
  rejected?: boolean;
  questionName?: string;
  headerTrack?: Array<Track>;
}

export interface SpecialTag {
  /** 第几张图 */
  offsetIndex: number;
  /** 左上角为原点(原图的原点)，及相对原图的位置比例 */
  offsetX: number;
  offsetY: number;
  /** 相对裁切图的位置比例 */
  positionX: number;
  positionY: number;
  /** 特殊标记的字符串，勾叉 */
  tagName: string;
  tagType: 'TEXT' | 'CIRCLE' | 'RIGHT' | 'WRONG' | 'HALF_RIGTH' | 'LINE';
  // 分组号
  groupNumber?: number;
  userId?: number;
  color?: string;
  isByMultMark?: boolean;
}

export interface Task {
  /** 学生ID */
  studentId: string;
  /** 任务编号 */
  secretNumber: string;
  /** 学生名称 */
  studentName: string;
  /** 学生编号 */
  studentCode: string;
  /** 科目名称 */
  courseName: string;
  /** 科目编号 */
  courseCode: string;
  /** 试卷编号 */
  paperNumber: string;
  /** 最高显示优先级，有sliceConfig就用sliceConfig，否则使用sheetConfig */
  sliceConfig: Array<SplitConfig>;
  jsonUrl: string;
  questionList: Array<Question>;
  specialTagList: Array<SpecialTag>;
  /** 原图url */
  sheetUrls: Array<string>;
  /** 客观分 复核也用到 */
  objectiveScore: number;
  /** 评卷总分 */
  markerScore: number;
  /** 评卷时间 */
  markerTime: number;
}

export type StudentObjectiveInfo = {
  studentId: string;
  studentName: string;
  studentCode: string;
  campusName: string;
  courseCode: string;
  courseName: string;
  paperNumber: string;
  objectiveScore: number;
  subjectiveScore: number;
  upload: boolean;
  absent: boolean;
  paperType: string;
  sheetUrls: Array<{ index: number; url: string; recogData: string }>;
  answers: Array<{
    mainNumber: number;
    subNumber: string;
    answer: string;
    exist: boolean;
    questionType: string;
    standardAnswer: string;
    score: number;
    totalScore: number;
  }>;
  titles: { [index: number]: string };
  success: boolean;
};

// card --------->

// page --------->
export interface TrackExportListFilter {
  semesterId: string;
  examId: string;
  courseId: string;
}
export type TrackExportListParams = PageParams<TrackExportListFilter>;

export interface TrackExportItem {
  examId: string;
  courseCode: string;
  courseName: string;
  paperNumber: string;
  studentCount: number;
}
export type TrackExportListPageRes = PageResult<TrackExportItem>;

export interface TrackExportDetailListFilter {
  examId: string;
  paperNumber: string;
  college?: string;
  majorName?: string;
  teachClassName?: string;
  className?: string;
  studentName?: string;
  studentCode?: string;
  startStudentCode?: string;
  endStudentCode?: string;
  startScore?: number;
  endScore?: number;
  objectiveStartScore?: number;
  objectiveEndScore?: number;
  subjectiveStartScore?: number;
  subjectiveEndScore?: number;
  orderType?: string;
  orderField?: string;
}

export type TrackExportDetailListParams =
  PageParams<TrackExportDetailListFilter>;

export interface TrackExportDetailItem {
  teachClassName: string; // 教学班
  className: string; // 行政班
  college: string;
  courseCode: string;
  courseName: string;
  examEndTime: number;
  examStartTime: number;
  majorName: number;
  studentCode: string;
  studentId: string;
  studentName: string;
  sheetUrls: string[] | null;
  totalScore: number;
}
export type TrackExportDetailListPageRes = PageResult<TrackExportDetailItem>;
