import { PageResult, PageParams, ExamSubjectParams } from "./common";
import { RecognizeArea } from "@/utils/recog/recog";

export interface RecognizeConditionItem {
  code: string;
  name: string;
  needValue: boolean;
}

export interface RecognizeCheckTaskConditionItem {
  code: string;
  name: string;
  value: number | null;
}

// 识别对照管理
export interface RecognizeCheckListItem {
  id: number;
  conditions: RecognizeCheckTaskConditionItem[];
  subjectCode: string;
  subjectName: string;
  // 默认任务组为true，不能修改删除，自动生成任务
  // 非默认任务组允许手动生成任务
  fixed: boolean;
  // 初始阶段为FIRST
  stage: string;
  // 是否正在重置任务
  reseting: boolean;
  // 是否正在生成任务
  building: boolean;
  // 是否正在删除
  deleting: boolean;
  totalCount: number;
  finishCount: number;
  unarbitrateCount: number;
  arbitratedCount: number;
  updateTime: number;
}
export type RecognizeCheckListPageResult = PageResult<RecognizeCheckListItem>;

export interface RecognizeCheckTaskSetConditionItem {
  code: string;
  name: string;
  needValue: boolean;
  value: number | null;
}

export interface RecognizeCheckTaskSaveParams {
  // 没有id则表示新增
  id?: number;
  examId: number;
  subjectCode: string;
  conditions: RecognizeCheckTaskSetConditionItem[];
}

export interface RecognizeCheckTaskActionResult {
  id: number;
  updateTime: number;
}
export interface RecognizeCheckBuildTaskResult
  extends RecognizeCheckTaskActionResult {
  building: boolean;
}
export interface RecognizeCheckResetTaskResult
  extends RecognizeCheckTaskActionResult {
  reseting: boolean;
}
export interface RecognizeCheckDeleteTaskResult
  extends RecognizeCheckTaskActionResult {
  deleting: boolean;
}

// 仲裁
export interface RecognizeArbitrateItemPage {
  index: number;
  uri: string;
  // 字段为null表示不需要仲裁处理
  absent: boolean[] | null;
  breach: boolean[] | null;
  paperType: string[] | null;
  // key为识别结果集中的序号，从1开始
  // 仲裁任务value数组有两个结果，分别表示一评和二评结果
  question: Record<number, string[]>;
  // selective: string[] | null;
  recogData: string;
}

export interface RecognizeArbitrateItem {
  // 任务ID
  id: number;
  examNumber: string;
  name: string;
  studentCode: string;
  subjectCode: string;
  subjectName: string;
  // 考生最新使用的卡格式编号
  cardNumber: number;
  paperId: number;
  paperNumber: number;
  pages: RecognizeArbitrateItemPage[];
}

export interface RecognizeArbitrateSavePage {
  index: number;
  // 与任务对应，有需要处理的才传递结果，否则为null
  // 所有需要仲裁的处理项需要全部提交
  absent: boolean | null;
  breach: boolean | null;
  paperType: string | null;
  question: Record<number, string>;
  selective: boolean | null;
}
export interface RecognizeArbitrateSaveParams {
  id: number;
  pages: RecognizeArbitrateSavePage[];
}

export interface RecognizeArbitrateSaveResult
  extends RecognizeCheckTaskActionResult {
  status: string;
}

export interface RecognizeArbitrateProgressResult {
  finishCount: number;
  todoCount: number;
}

export interface RecognizeArbitrateHistoryParams {
  groupId: number;
  id?: number;
  next?: boolean;
}

export interface RecognizeArbitrateTaskDetail extends RecognizeArea {
  index: number;
  result1: string;
  result2: string;
  pageIndex: number;
  groupId: number;
  uri: string;
}
