import { BaseDefine, MultipleQuery, MultipleResult } from './base'

/** 评卷相关 */
export namespace Marking {
  /** 自定义查询 - 抽查 */

  // 查询参数
  interface CustomQuery {
    /** 是否包含仲裁 */
    arbitration?: boolean
    /** 是否已抽查 */
    checked?: boolean
    /** 大题号 */
    mainNumber?: number
    /** 评卷员id */
    markerId?: number
    /** 小组号 */
    markingGroupNumber?: number
    /** 分数截止 */
    scoreEnd?: number
    /** 分数开始 */
    scoreStart?: number
    /** 科目代码 */
    subjectCode?: string
    /** 时间截止 */
    timeEnd?: string
    /** 时间开始 */
    timeStart?: string
    /** 密号 */
    secretNumber?: string
  }

  /** 自定义抽查任务列表 */
  interface CustomQueryTask {
    customCheckNumber: number
    examNumber: string
    filePath: string
    mainNumber: number
    markTime: string
    markerName: string
    headerScore: number
    markerScore: number
    secretNumber: string
    taskId: number
  }
  type GetCustomQueryTasks = BaseDefine<MultipleQuery<CustomQuery>, MultipleResult<CustomQueryTask>>

  type SetCustomQueryConfig = BaseDefine<{ name: string; params: CustomQuery }>

  type GetCustomQueryConfigList = BaseDefine<{ name: string }, { name: string; params: CustomQuery }[]>

  /** 自定义查询 - 浏览 */
  type ViewCustomQuery = BaseDefine<{ taskId: number }>

  /** 自定义查询 - 修改卷型 */
  type UpdateCustomPaperType = BaseDefine<{
    taskId?: number
    paperType: ExpertPickType
    forceGroupNumber?: number
  }>

  /** 自定义查询 - 修改分数 */
  type UpdateCustomPaperScore = BaseDefine<{
    taskId?: number
    scores: number[]
  }>

  type GetMarkingStandard = BaseDefine<null, { examId: number; mainNumber: number; subjectCode: string; url: string }>

  interface Question {
    intervalScore: number
    subNumber: string
    totalScore: number
  }
  interface Task {
    /** 大题号 */
    mainNumber: number
    /** 大题名称 */
    mainTitle: string
    /** 小题列表 */
    questionList: Question[]
    /** 密号 */
    secretNumber: string
    /** 科目代码 */
    subjectCode: string
    /** 任务ID */
    taskId: number
    /** 任务类型 */
    taskType: TaskType
    /** 最小阅卷时长 */
    minMarkTime: number
    /** 试卷 path */
    url: string
  }

  type GetMarkingTask = BaseDefine<null, Task[]>

  /** 清除评卷任务缓存 */
  type ClearCachedTasks = BaseDefine

  interface MarkStatus {
    markedCount: number
    personCount: number
    problemCount: number
    totalCount: number
  }

  type GetMarkStatus = BaseDefine<null, MarkStatus>

  interface SubmitMark {
    markScore: number
    markScores: number[]
    spentTime: number
    taskId: number
    taskType: TaskType
    problem: boolean
    problemType?: ProblemType
  }

  type SubmitMarkTask = BaseDefine<SubmitMark, { refresh: boolean }>

  interface HistoryTask {
    mainNumber: number
    mainTitle: number
    markScore: number
    markTime: string
    markerScores: number[]
    questionList: Question[]
    secretNumber: string
    subjectCode: string
    taskId: number
    taskType: TaskType
    url: string
  }

  type GetMarkHistory = BaseDefine<null, HistoryTask[]>

  interface ProblemListParams {
    mainNumber?: number
    problemType: ProblemType | ''
    status: '' | 'INITIAL' | 'PROCESSED'
  }

  interface ProblemListItem {
    markTime: string
    examNumber: string
    filePath: string
    headerName: number
    headerScore: number
    headerScores: number[]
    id: number
    mainNumber: number
    mainName: string
    markerName: string
    markRatio: string
    markScore: number
    objectiveScore: number
    problemSolveType: string
    problemType: string
    problemTypeName: string
    secretNumber: string
    solveTime: string
    taskId: number
  }

  type GetProblemHistory = BaseDefine<MultipleQuery<ProblemListParams>, MultipleResult<ProblemListItem>>

  type MarkProblemPaper = BaseDefine<{ id?: number; scores: number[] }>

  /** 问题卷浏览 */
  type ViewProblemPaper = BaseDefine<{ id: number }>

  interface MarkScoreHistory {
    id: number
    markScore: number
    markerName: string
    scoreLevel: 'LEVEL_1' | 'LEVEL_2' | 'LEVEL_3' | 'LEVEL_4' | 'LEVEL_5'
    markTime: string
    secretNumber: string
    status: string
    taskId: number
    url: string
  }

  type GetMarkScoreHistoryListWithTask = BaseDefine<{ taskId: number | string }, MarkScoreHistory[]>

  type RejectMarkHistory = BaseDefine<{ description: string; id: number; reason: string }>

  interface ArbitrationListItem {
    chiefName: string
    chiefRatio: string
    chiefScore: number
    deputyName: string
    deputyRatio: string
    deputyScore: number
    filePath: string
    groupLeaderName: string
    groupLeaderRatio: string
    groupLeaderScore: number
    id: number
    mainName: string
    mainNumber: number
    markerName: string
    markerRatio: string
    markerScore: number
    objectiveScore: number
    secretNumber: string
    status: string
    taskId: number
    teamLeaderName: string
    teamLeaderRatio: string
    teamLeaderScore: number
  }

  type GetArbitrationList = BaseDefine<
    MultipleQuery<{ mainNumber?: number; status: ArbitrationStatus | '' }>,
    MultipleResult<ArbitrationListItem>
  >

  type MarkArbitrationPaper = BaseDefine<{ id?: number; scores: number[] }>

  type ViewArbitrationPaper = BaseDefine<{ id?: number }>

  interface ReMarkPaperListItem {
    confirm: string
    confirmScore: number
    filePath: string
    id: number
    mainNumber: number
    mainName: string
    markerName: string
    markerScore: number
    reMarkTime: string
    secretNumber: string
    taskId: number
  }

  type GetReMarkPaperList = BaseDefine<
    MultipleQuery<{ mainNumber?: number; confirm: boolean }>,
    MultipleResult<ReMarkPaperListItem>
  >

  type MarkReMarkPaper = BaseDefine<{ id?: number; scores: number[] }>

  type ConfirmReMarkPaper = BaseDefine<{ id?: number }>

  interface TrainingRecord {
    examId: number
    markScore: number
    score: number
    secretNumber: string
    subjectCode: string
    taskId: number
    taskType: string
    url: string
  }

  type ViewTrainingRecord = BaseDefine<null, TrainingRecord[]>

  interface SamplePaper {
    description: string
    examId: number
    id: number
    mainNumber: number
    mainTitle: string
    markTime: string
    markerName: string
    score: number
    secretNumber: number
    subjectCode: string
    url: string
  }

  type ViewSamplePaper = BaseDefine<null, SamplePaper[]>

  interface SamePaperListItem {
    examNumber: string
    filePath: string
    id: number
    mainNumber: number
    markerName: string
    sameExamNumber: string
    sameFilePath: string
    sameSecretNumber: string
    secretNumber: number
    status: 'INITIAL' | 'NOT_SAME' | 'SAME'
    taskId: number
  }

  type GetSimilarPaperList = BaseDefine<
    MultipleQuery<{
      mainNumber?: number
      status: 'INITIAL' | 'NOT_SAME' | 'SAME' | '' | null
    }>,
    MultipleResult<SamePaperListItem>
  >

  type ConfirmIsSimilar = BaseDefine<{ id?: number; same: boolean }>

  type ExportSimilarPaper = BaseDefine<
    MultipleQuery<{
      mainNumber?: number
      status: 'INITIAL' | 'NOT_SAME' | 'SAME' | '' | null
    }>
  >

  type SubmitSimilarPaper = BaseDefine<{ sameTaskId: number | string; taskId: number | string }>

  export interface ApiMap {
    /** 自定义查询 - 抽查 */
    getCustomQueryTasks: GetCustomQueryTasks
    /** 自定义查询 - 保存为快捷查询 */
    setCustomQueryConfig: SetCustomQueryConfig
    /** 自定义查询 - 获取快捷查询列表 */
    getCustomQueryConfigList: GetCustomQueryConfigList
    /** 自定义查询 - 浏览 */
    viewCustomQuery: ViewCustomQuery
    /** 自定义查询 - 修改卷型 */
    updateCustomPaperType: UpdateCustomPaperType
    /** 自定义查询 - 修改分数 */
    updateCustomPaperScore: UpdateCustomPaperScore
    /** 查看评分标准 */
    getMarkingStandard: GetMarkingStandard
    /** 获取评卷任务 */
    getMarkingTask: GetMarkingTask
    /** 清除评卷任务缓存 */
    clearCachedTasks: ClearCachedTasks
    /** 获取评卷进度 */
    getMarkStatus: GetMarkStatus
    /** 提交评卷任务 */
    submitMarkTask: SubmitMarkTask
    /** 获取回评历史 */
    getMarkHistory: GetMarkHistory
    /** 问题卷列表 */
    getProblemHistory: GetProblemHistory
    /** 问题卷打分 */
    markProblemPaper: MarkProblemPaper
    /** 问题卷浏览 */
    viewProblemPaper: ViewProblemPaper
    /** 通过taskId 查询给分记录 */
    getMarkScoreHistoryListWithTask: GetMarkScoreHistoryListWithTask
    /** 打回 */
    rejectMarkHistory: RejectMarkHistory
    /** 仲裁卷列表 */
    getArbitrationList: GetArbitrationList
    /** 仲裁卷打分 */
    markArbitrationPaper: MarkArbitrationPaper
    /** 仲裁卷浏览 */
    viewArbitrationPaper: ViewArbitrationPaper
    /** 重评卷列表 */
    getReMarkPaperList: GetReMarkPaperList
    /** 重评卷打分 */
    markReMarkPaper: MarkReMarkPaper
    /** 重评卷确认 */
    confirmReMarkPaper: ConfirmReMarkPaper
    /** 查看培训记录 */
    viewTrainingRecord: ViewTrainingRecord
    /** 查看样卷 */
    viewSamplePaper: ViewSamplePaper
    /** 雷同卷列表 */
    getSimilarPaperList: GetSimilarPaperList
    /** 是否雷同 */
    confirmIsSimilar: ConfirmIsSimilar
    /** 导出雷同 */
    exportSimilarPaper: ExportSimilarPaper
    /** 提交雷同卷 */
    submitSimilarPaper: SubmitSimilarPaper
  }
}
