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

/** 监控分析 */
export namespace Statistics {
  interface BaseFilterOption {
    subjectCode?: string
    questionMainNumber?: number
    markingGroupNumbers?: number[]
  }

  /** 质量统计-自查一致性分析 */
  interface SelfCheckAnalysisReq {
    /** 结束时间，格式：yyyyMMddHHmmss */
    endTime: string
    /** 小组号 */
    markingGroupNumber?: number
    /** 大题号 */
    questionMainNumber?: number
    /** 开始时间，格式：yyyyMMddHHmmss */
    startTime: string
    /** 科目代码 */
    subjectCode: string
  }
  interface SelfCheckAnalysisResponse {
    /** 平均离差 */
    avgDiff: number
    /** 自查份数 */
    checkCount: number
    /** 评卷员ID */
    markerId: number
    /** 评卷员名称 */
    markerName: string
  }

  type SelfCheckAnalysis = BaseDefine<SelfCheckAnalysisReq, SelfCheckAnalysisResponse[]>

  interface SelfCheckAnalysisDiffListItemPaper {
    diff: number
    lastMarkScore: number
    markScore: number
    markTime: string
    secretNumber: string
    taskId: number
  }

  interface SelfCheckAnalysisDiffListItem {
    diff: number
    papers: SelfCheckAnalysisDiffListItemPaper[]
  }

  type SelfCheckAnalysisDiffList = BaseDefine<
    {
      markerId?: number
      questionMainNumber?: number
      subjectCode: string
    },
    SelfCheckAnalysisDiffListItem[]
  >

  /** 质量分析 - 自查数据详情 */
  interface SelfCheckDataDetail {
    diff: number
    filePath: string
    mainName: string
    mainNumber: number
    markTime: string
    markerName: string
    markerScore: number
    secretNumber: string
    selfScore: number
    taskId: number
  }
  type GetSelfCheckDataDetail = BaseDefine<
    {
      subjectCode: string
      mainNumber: number | string
      markingGroupNumber: number | string
      startTime: string
      endTime: string
      taskId?: number
    },
    SelfCheckDataDetail[]
  >

  /** 质量统计-自查数据打分 */
  type MarkSelfCheckData = BaseDefine<{ taskId?: number; scores: number[] }>

  /** 质量统计-自查数据打回 */
  type RejectSelfCheckData = BaseDefine<{ id?: number; reason: string; description: string }>

  /** 质量分析- 抽查情况统计 */
  interface StatisticCheckInfo {
    customCheckCount: number
    customCheckReScoreCount: number
    markerId: number
    markerName: string
    questionMainName: string
    questionMainNumber: number
    rejectCount: number
    sysCheckCount: number
    sysCheckReScoreCount: number
  }

  type StatisticCheckOverview = BaseDefine<
    {
      questionMainNumber?: number
      subjectCode: string
      markingGroupLeaderId?: number
    },
    StatisticCheckInfo[]
  >
  /** 质量统计-主观题校验列表 */
  interface SubjectiveListItem {
    filePath: string
    headerName: string
    headerScore: number
    mainName: string
    mainNumber: number
    markScore: number
    secretNumber: number
    status: string
    taskId: number
    updateTime: string
  }

  type GetSubjectiveCheckList = BaseDefine<
    MultipleQuery<{
      subjectCode: string
      mainNumber?: number
      checked?: boolean
      rule: 'RULE1' | 'RULE2' | 'RULE3' | 'RULE4'
    }>,
    MultipleResult<SubjectiveListItem>
  >

  type SubjectiveCheckMark = BaseDefine<{ taskId?: number; scores: number[] }>

  type SubjectiveCheckConfirm = BaseDefine<{ taskId?: number }>

  /** 决策分析-评卷进度统计（整体） */
  interface MarkProgressResponse {
    /** 已完成数 */
    finishCount: number
    /** 完成比率 */
    finishRate: number
    /** 大题名称 */
    questionMainName: string
    /** 大题号 */
    questionMainNumber: number
    /** 预计耗时（秒） */
    takeTime: number
    /** 试卷总量 */
    totalPaper: number
  }

  type GetMarkProgress = BaseDefine<{ subjectCode: string }, MarkProgressResponse[]>

  /** 决策分析-评卷进度统计（按小组） */
  interface MarkProgressByGroup {
    dayFinishCount: number
    dayFinishRate: number
    finishCount: number
    finishRate: number
    markingGroupNumber: number
  }

  type GetMarkProgressByGroup = BaseDefine<{ subjectCode: string; questionMainNumber?: number }, MarkProgressByGroup[]>

  /** 决策分析-评卷进度统计（按评卷员） */
  interface MarkProgressByMarker {
    dayFinishCounts: { count: number; date: string }[]
    markerId: number
    markerName: string
    markingGroupNumber: number
    totalFinishCount: number
  }
  type GetMarkProgressByMarker = BaseDefine<
    { subjectCode: string; questionMainNumber?: number; markingGroupNumber?: number },
    MarkProgressByMarker[]
  >

  type ExportMarkProgressByMarker = BaseDefine<{
    subjectCode: string
    questionMainNumber?: number
    markingGroupNumber?: number
  }>

  /** 科目进度收尾 */
  interface SubjectProgressEndInfo {
    arbitrationPaperRate: number
    checkPaperCount: number
    checkPaperRate: number
    finishCount: number
    finishRate: number
    questionMainName: string
    questionMainNumber: number
    subjectiveUnVerifyPaperCount: number
    todoArbitrationPaperCount: number
    todoProblemPaperCount: number
    todoSamePaperCount: number
    totalPaper: number
  }

  type SubjectProgressEnd = BaseDefine<{ subjectCode: string }, SubjectProgressEndInfo[]>

  interface BaseParams {
    subjectCode: string
    questionMainNumber?: number
    markingGroupNumber?: number
  }

  /** 质量统计-收尾检查-评卷员未评卷列表（分页） */

  interface UnMarkPaper {
    markerId: number
    markerName: string
    questionMainName: string
    questionMainNumber: number
    secretNumber: string
    taskId: number
  }
  type UnMarkPaperList = BaseDefine<MultipleQuery<BaseParams>, MultipleResult<UnMarkPaper>>
  /** 质量统计-收尾检查-未处理雷同卷列表 */
  interface UnProcessSimilar {
    questionMainName: string
    questionMainNumber: number
    sameSecretNumber: string
    secretNumber: string
  }
  type UnProcessSimilarList = BaseDefine<BaseParams, UnProcessSimilar[]>
  /** 质量统计-收尾检查-未处理问题卷列表 */
  interface UnProcessProblem {
    questionMainName: string
    questionMainNumber: number
    secretNumber: string
  }
  type UnProcessProblemList = BaseDefine<BaseParams, UnProcessProblem[]>

  type ChangeTaskMarker = BaseDefine<{ loginName: string; taskId?: number }>

  /** 小组监控 */
  interface GroupMonitor {
    /** 已浏览自定义抽查卷数 */
    customCheckCount: number
    /** 已浏览问题卷数 */
    problemCount: number
    /** 已浏览系统抽查卷数 */
    sysCheckCount: number
    /** 组长 */
    markingGroupLeader: string
    /** 组长ID */
    markingGroupLeaderId: string
    /** 小组号 */
    markingGroupNumber: number
    /** 已给分自定义抽查卷数 */
    customCheckReScoreCount: number
    /** 已给分问题卷数 */
    problemReScoreCount: number
    /** 已给分系统抽查卷数 */
    sysCheckReScoreCount: number
    /** 已浏览试卷总数 */
    totalCount: number
    /** 已给分试卷总数 */
    totalReScoreCount: number
  }
  type GetGroupMonitor = BaseDefine<BaseFilterOption, GroupMonitor[]>

  /** 小组监控 - 抽查详情 */
  interface GroupMonitorDetail {
    filePath: string
    headerRatio: string
    headerScore: number
    mainName: string
    mainNumber: number
    markTime: string
    markerId: number
    markerName: string
    markerScore: number
    objectiveScore: number
    scoreLevel: string
    secretNumber: string
    taskId: number
  }

  type GetGroupMonitorDetail = BaseDefine<
    MultipleQuery<{ operateType: 'VIEW' | 'MARK'; headerId: string | number }>,
    MultipleResult<GroupMonitorDetail>
  >

  type MarkMonitorDetailTask = BaseDefine<{ taskId?: number; scores: number[] }>

  /** 决策分析- 统计 */
  interface StatisticItem {
    markerId: number
    markerName: string
    value: number
  }

  type GetStatistics = BaseDefine<BaseFilterOption, Record<string, StatisticItem[]>>

  /** 决策分析-监控统计（按小组） */
  interface GetStatisticsByGroupParams {
    endTime?: string
    hasJudge?: boolean
    markerId?: number
    markingGroupNumbers?: number[]
    questionMainNumber?: number
    startTime?: string
    subjectCode: string
  }

  interface GetStatisticsByGroupResponseItem {
    /** 平均分 */
    avg: number
    /** 抽查改正量 */
    checkCorrectCount: number
    /** 抽查量 */
    checkCount: number
    /** 综合指数 */
    integration: number
    /** 评卷员ID */
    markerId: number
    /** 评卷员名称 */
    markerName: string
    /** 小组号 */
    markingGroupNumber: number
    /** 评卷份数 */
    markingPaperCount: number
    /** 评卷速度（n秒每个） */
    markingRate: number
    /** 评卷状态 */
    markingStatus: string
    /** 平均客主比 */
    objSubAvgRate: number
    /** 客主比（近N分钟） */
    objSubRate: number
    /** 客观平均分 */
    objectiveAvg: number
    /** 客观标准差 */
    objectiveStd: number
    /** 客观0分量 */
    objectiveZero: number
    /** 是否在线 */
    online: boolean
    /** 重评待确认量 */
    reMarkUnConfirmCount: number
    /** 重评量 */
    reMarkCount: number
    /** 最低分（近N分钟） */
    scoreLow: number
    /** 最高分（近N分钟） */
    scoreTop: number
    /** 方差 */
    sd: number
    /** 标准差 */
    std: number
    /** 相关系数 */
    xyRelate: number
    /** 评卷员明细统计列表 */
    markerDetails: GetStatisticsByGroupResponseItem[] | null
  }

  type GetStatisticsByGroup = BaseDefine<GetStatisticsByGroupParams, GetStatisticsByGroupResponseItem[]>

  /** 决策分析-监控统计导出（按小组） */
  type ExportStatisticsByGroup = BaseDefine<GetStatisticsByGroupParams>

  /** 培训监控 */
  interface TrainingMonitorParams {
    subjectCode: string
    mainNumber?: number
    markingGroupNumber?: number
    markStage: 'SAMPLE_A' | 'SAMPLE_B' | 'FORCE'
    forceGroupNumber?: number
  }
  interface TrainingMonitorResponse {
    /** 平均分 */
    avg: number
    /** 差异份数 */
    diffCount: number
    forceGroupMarkerId: number
    /** 评卷员ID */
    markerId: number
    /** 评卷员名称 */
    markerName: string
    /** 打分列表 */
    scoreList: number[]
    /** 状态 */
    stage: 'SAMPLE_A' | 'SAMPLE_B' | 'FORCE'
    /** 状态名称 */
    status: string
    /** 标准差 */
    std: number
    /** 相关系数 */
    xyRelate: number
  }
  type GetTrainingMonitor = BaseDefine<TrainingMonitorParams, { data: TrainingMonitorResponse[]; header: number[] }>

  interface MonitorDetail {
    fileName: string
    filePath: string
    forceGroupNumber: number
    group: string
    mainNumber: number
    markTime: string
    markerName: string
    markScore: number
    score: number
    secretNumber: string
    taskId: number
  }

  /**培训监控 - 培训卷调卷详情 */
  type GetTrainingMonitorDetail = BaseDefine<{ markerId: string; taskType: SamplePaperType }, MonitorDetail[]>

  /**培训监控 - 强制考核卷调卷详情 */
  type GetAssessMonitorDetail = BaseDefine<{ forceGroupMarkerId: string }, MonitorDetail[]>

  /**培训监控 - 强制考核卷审核 */
  type PutAssessMonitorPass = BaseDefine<{ forceGroupMarkerIds: number[]; pass: boolean }>

  /**培训监控 - 培训卷审核 */
  type PutSampleMonitorPass = BaseDefine<{ markerIds: number[]; markStage: SamplePaperType; pass: boolean }>

  /** 个人统计 */
  interface PersonalStatistic {
    avg: number
    markerId: number
    markerName: string
    markingPaperCount: number
    markingRate: number
    questionMainName: string
    questionMainNumber: number
  }
  type GetPersonalStatistic = BaseDefine<{ startTime: string; endTime: string; markerId?: number }, PersonalStatistic>

  /** 提取阅卷明细 */
  interface PersonalMarkDetail {
    filePath: string
    mainName: string
    mainNumber: number
    markTime: string
    markerName: string
    markerRatio: string
    markerScore: number
    objectiveScore: number
    secretNumber: string
    status: string
    taskId: number
  }

  type GetPersonalMarkDetail = BaseDefine<
    MultipleQuery<{
      markerId?: number | string
      score?: number | string
    }>,
    MultipleResult<PersonalMarkDetail>
  >

  type UpdatePersonalMarkDetailScore = BaseDefine<{ taskId?: number; scores: number[] }>

  interface SystemSpotListItem {
    examNumber: string
    filePath: string
    id: number
    mainNumber: number
    markScore: number
    markTime: string
    markerName: string
    secretNumber: number
    status: string
    taskId: number
  }

  type GetSystemSpotList = BaseDefine<
    MultipleQuery<{
      level: 'LEVEL_1' | 'LEVEL_2' | 'LEVEL_3' | 'LEVEL_4' | 'LEVEL_5' | ''
      status: 'INITIAL' | 'VIEWED' | 'GRADED' | 'REJECT'
      mainNumber?: number
    }>,
    MultipleResult<SystemSpotListItem>
  >

  /** 系统抽查卷打分 */
  type MarkSystemSpotPaper = BaseDefine<{ id?: number; scores: number[] }>

  /** 系统抽查卷打回 */
  type RejectSystemSpotPaper = BaseDefine<{ description: string; id: number; reason: string }>

  /** 系统抽查卷浏览 */
  type ViewSystemSpotPaper = BaseDefine<{ id?: number }>

  interface StatisticByGroup {
    subjectCode: string
    questionMainNumber?: number
    markingGroupNumber?: number
    startTime: string
    endTime: string
  }

  interface StatisticByMarker {
    markerId?: number
    endTime: string
    startTime: string
  }

  interface StatisticInfo {
    count: number
    rate: number
    scoreEnd: number
    scoreStart: number
  }

  interface StatisticResult {
    segmentsByAll: StatisticInfo[]
    segmentsByGroup: StatisticInfo[]
    segmentsByUser: StatisticInfo[]
  }

  /** 决策分析-监控统计-客观题分数分布（按小组） */
  type GetStatisticObjectiveByGroup = BaseDefine<StatisticByGroup, StatisticResult>

  /** 决策分析-监控统计-客观题分数分布（按评卷员） */
  type GetStatisticObjectiveByMarker = BaseDefine<StatisticByMarker, StatisticResult>

  /** 决策分析-监控统计-主观题分数分布（按小组） */
  type GetStatisticSubjectiveByGroup = BaseDefine<StatisticByGroup, StatisticResult>

  /** 决策分析-监控统计-主观题分数分布（按评卷员） */
  type GetStatisticSubjectiveByMarker = BaseDefine<StatisticByMarker, StatisticResult>

  interface ApiMap {
    /** 质量统计-自查一致性分析 */
    selfCheckAnalysis: SelfCheckAnalysis
    /** 质量统计-自查一致性分析-离差列表 */
    selfCheckAnalysisDiffList: SelfCheckAnalysisDiffList
    /** 质量统计- 自查数据详情 */
    getSelfCheckDataDetail: GetSelfCheckDataDetail
    /** 质量统计-自查数据打分 */
    markSelfCheckData: MarkSelfCheckData
    /** 质量统计-自查数据打回 */
    rejectSelfCheckData: RejectSelfCheckData
    /** 质量统计-抽查情况统计 */
    statisticCheckOverview: StatisticCheckOverview
    /** 质量统计-主观题校验 */
    getSubjectiveCheckList: GetSubjectiveCheckList
    /** 质量统计-主观题校验打分 */
    subjectiveCheckMark: SubjectiveCheckMark
    /** 质量统计-主观题校验确认 */
    subjectiveCheckConfirm: SubjectiveCheckConfirm
    /** 决策分析-评卷进度统计（整体） */
    getMarkProgress: GetMarkProgress
    /** 决策分析-评卷进度统计（按小组） */
    getMarkProgressByGroup: GetMarkProgressByGroup
    /** 决策分析-评卷进度统计（按评卷员） */
    getMarkProgressByMarker: GetMarkProgressByMarker
    /** 决策分析-评卷进度统计导出（按评卷员） */
    exportMarkProgressByMarker: ExportMarkProgressByMarker
    /** 质量统计-科目进度收尾 */
    subjectProgressEnd: SubjectProgressEnd
    /** 质量统计-收尾检查-评卷员未评卷列表（分页） */
    unMarkPaperList: UnMarkPaperList
    /** 质量统计-收尾检查-未处理雷同卷列表 */
    unProcessSimilarList: UnProcessSimilarList
    /** 质量统计-收尾检查-未处理问题卷列表 */
    unProcessProblemList: UnProcessProblemList
    /** 任务指定新评卷员 */
    changeTaskMarker: ChangeTaskMarker
    /** 决策分析-小组监控 */
    getGroupMonitor: GetGroupMonitor
    /** 决策分析-小组监控-抽查详情 */
    getGroupMonitorDetail: GetGroupMonitorDetail
    /** 决策分析-小组监控-抽查详情给分 */
    markMonitorDetailTask: MarkMonitorDetailTask
    /** 决策分析-监控统计（整体） */
    getStatistics: GetStatistics

    /** 决策分析-监控统计（按小组） */
    getStatisticsByGroup: GetStatisticsByGroup
    /** 决策分析-监控统计导出（按小组） */
    exportStatisticsByGroup: ExportStatisticsByGroup
    /** 决策分析-监控统计客观题&主观题分数分布 */
    /**培训监控 */
    getTrainingMonitor: GetTrainingMonitor
    /**培训监控 - 培训卷调卷详情 */
    getTrainingMonitorDetail: GetTrainingMonitorDetail
    /**培训监控 - 强制考核卷调卷详情 */
    getAssessMonitorDetail: GetAssessMonitorDetail
    /**培训监控 - 强制考核卷审核 */
    putAssessMonitorPass: PutAssessMonitorPass
    /**培训监控 - 培训卷审核 */
    putSampleMonitorPass: PutSampleMonitorPass
    /** 个人统计 */
    getPersonalStatistic: GetPersonalStatistic
    /** 提取阅卷明细 */
    getPersonalMarkDetail: GetPersonalMarkDetail
    /** 提取阅卷明细 - 给分 */
    updatePersonalMarkDetailScore: UpdatePersonalMarkDetailScore
    /** 系统抽查卷 */
    getSystemSpotList: GetSystemSpotList
    /** 系统抽查卷打分 */
    markSystemSpotPaper: MarkSystemSpotPaper
    /** 系统抽查卷打回 */
    rejectSystemSpotPaper: RejectSystemSpotPaper
    /** 系统抽查卷浏览 */
    viewSystemSpotPaper: ViewSystemSpotPaper
    /** 决策分析-监控统计-客观题分数分布（按小组） */
    getStatisticObjectiveByGroup: GetStatisticObjectiveByGroup
    /** 决策分析-监控统计-客观题分数分布（按评卷员） */
    getStatisticObjectiveByMarker: GetStatisticObjectiveByMarker
    /** 决策分析-监控统计-主观题分数分布（按小组） */
    getStatisticSubjectiveByGroup: GetStatisticSubjectiveByGroup
    /** 决策分析-监控统计-主观题分数分布（按评卷员） */
    getStatisticSubjectiveByMarker: GetStatisticSubjectiveByMarker
  }
}
