import { PageResult, PageParams, ExamSubjectParams } from "./common";

export type DataStatus = "SCANNED" | "UNEXIST" | "MANUAL_ABSENT";
export type ExamStatus = "OK" | "ABSENT" | "UNCHECK";
export type PaperTypeStatus = "OK" | "BLANK" | "ERROR";

export interface DataCheckListFilter {
  examId: number;
  status: DataStatus[];
  examStatus: ExamStatus[];
  examNumber: string;
  studentCode: string;
  name: string;
  packageCode: string;
  campusCode: string;
  subjectCode: string;
  examSite: string;
  examRoom: string;
  province: string;
  paperTypeStatus: PaperTypeStatus;
  device: string;
  absentSuspect: boolean;
  omrAbsent: boolean;
  assigned: boolean;
  incomplete: boolean;
  questionFilled: boolean;
  subjectiveFilled: boolean;
  hasFilled: boolean;
  withOmrDetail: boolean;
}

export type DataCheckListParams = PageParams<DataCheckListFilter>;

export interface PaperPageItem {
  index: number;
  sheetUri: string;
  sliceUri: string[];
  // withOmrDetail=true时有识别结果，显示最新的判定结果
  absent: {
    type: string;
    result: boolean;
  };
  breach: {
    type: string;
    result: boolean;
  };
  paperType: {
    type: string;
    result: string;
  };
  question: {
    result: string[];
    type: string;
  };
  selective: { type: string; result: string } | null;
  recogData: string | null;
}

// 某张缺页时没有id和pages等其他字段
export interface PaperItem {
  // 某张缺页时没有id和pages等其他字段
  id: number;
  number: number;
  // 是否人工绑定
  assigned?: boolean;
  // 各页图片与识别结果
  pages: PaperPageItem[];
}

export interface DataCheckListItem {
  id: number;
  examNumber: string;
  studentCode: string;
  name: string;
  subjectCode: string;
  subjectName: string;
  packageCode: string;
  campusCode: string;
  campusName: string;
  examSite: string;
  examSiteName: string;
  examRoom: string;
  seatNumber: number;
  examStatus: ExamStatus;
  // 扫描状态
  status: DataStatus;
  absentSuspect: boolean;
  omrAbsent: boolean;
  assigned: boolean;
  incomplete: boolean;
  // 识别试卷类型，若无则为null
  paperType: string;
  // 最新使用卡格式编号
  cardNumber: number;
  // 手动修改的管理员信息
  updator: string;
  updateTime: number;
  device: string;
  // 考生最新关联的各张图片
  papers: PaperItem[];
}

export type DataCheckListResult = PageResult<DataCheckListItem>;

export type OmrFiledType =
  | "ABSENT"
  | "REACH"
  | "PAPER_TYPE"
  | "SELECTIVE"
  | "QUESTION";

export interface DataCheckOmrFieldEditParams {
  examId: number;
  examNumber: string;
  paperNumber: string;
  pageIndex: number;
  subjectCode: string;
  field: OmrFiledType;
  value: string;
}

interface OmrEditPaperPageInfo {
  index: number;
  // 不修改的字段为null，否则需要提交完整结果
  // type与原始的卡格式定义相同
  absent: {
    type: "FILL_AREA";
    result: boolean;
  } | null;
  breach: boolean | null;
  paperType: {
    type: "BARCODE";
    result: string;
  } | null;
  question: {
    type: "FILL_AREA";
    result: string[];
  } | null;
  // selective: null;
}

interface OmrEditPaperInfo {
  number: number;
  pages: OmrEditPaperPageInfo[];
}

export interface DataCheckOmrEditParams {
  examId: number;
  examNumber: string;
  papers: OmrEditPaperInfo[];
}
