import { request } from 'umi';
import type { TableListItem } from './data';

/** 获取考试规则列表 GET  /dsideal_yy/zygh/training/examination/getExaminationList */
export async function queryRulesList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total_row?: number;
    /** 页面的容量 */
    page_size?: number;
    success?: boolean;
  }>('/dsideal_yy/zygh/training/rules/getRulesList', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 新建/修改考试 POST /dsideal_yy/zygh/training/rules/updateRules */
export async function saveRules(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/zygh/training/rules/updateRules', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}

/** 获取考试规则详情 */
export async function queryRulesView(
  params: {
    // query
    /** 当前的页码 */
    id?: number;
  },
  options?: Record<string, any>,
) {
  return request('/dsideal_yy/zygh/training/rules/getRulesById', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/**
 * 获取主题列表
 * http://10.10.14.252:8080/workspace/myWorkspace.do?projectId=382#6426
 * @param params
 * @returns
 */
export async function querySubjectList(params: {
  page_size: number;
  //count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/dsideal_yy/ypt/careerTraining/subject/listSubject', {
    params,
  });
}

/** 删除考试 POST /dsideal_yy/ypt/careerTraining/course/delete */
export async function removeExamination(data: { key: number[] }, options?: Record<string, any>) {
  return request<Record<string, any>>('/dsideal_yy/ypt/careerTraining/course/delete', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

/** 查看考试（仅仅获取考试详情，不标记浏览量）GET /dsideal_yy/ypt/careerTraining/course/view */
export async function queryExaminationView(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/ypt/careerTraining/course/view', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

/** 获取报名列表 GET Mock /api/queryRegistrationList */
export async function queryRegistrationList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/api/getRegistrationList', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 删除考试规则 */
export async function removeRules(data: { key: number[] }, options?: Record<string, any>) {
  console.log('data:::', data);
  return request<Record<string, any>>('/dsideal_yy/zygh/training/rules/delRules', {
    data: { id: data?.key[0], rules_type: options?.rules_type, subject_id: options?.subject_id}, // 当前接口不支持批量操作
    method: 'POST',
    requestType: 'form',
    ...(options || {}),
  });
}

/** 组卷，查询试题临时表（当前选题列表） */
export async function queryTempQuestionList(
  params: {
    paper_uuid: string; // paper_uuid参数不能为空
    page_size: number;
    page_number: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/dsideal_yy/zygh/training/rules/getTempQuestionList', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 19 组卷，删除临时表数据 */
export async function delTempQuestion(data: Record<string, any>, options?: Record<string, any>) {

  return request<TableListItem>('/dsideal_yy/zygh/training/rules/delTempQuestion', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}

/** 组卷详情查询 */
export async function queryRulesPaper(
  params: {
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/dsideal_yy/zygh/training/rules/getRulesPaper', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/**
 * 06 获取试卷内容
 *
 */
 export async function queryPaperQuestionList(
  params: {
    paper_id: string; // 试卷id
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/dsideal_yy/zygh/training/rules/getPaperQuestionList', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 组卷，修改题型分数 */
export async function saveQuestionTypeScore(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/zygh/training/rules/saveQuestionTypeScore', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}

/** 24 组卷，保存总分与通过线（也可以使用01接口维护） */
export async function updateScore(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/zygh/training/rules/updateScore', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}

/** 22 组卷，资质考试组卷 */
export async function autoPaperOfficial(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/zygh/training/rules/autoPaperOfficial', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}

/** 27 组卷，交换临时表顺序 */
export async function exchangeSortNum(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/zygh/training/rules/exchangeSortNum', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}

/** 16 组卷，查询试题数据（去掉已选列表）*/
export async function queryQuestionWithoutList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/dsideal_yy/zygh/training/rules/getQuestionList', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}


/** 资质考试规则设置获取题库题目数量*/
export async function getTypeQuestionCountList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/dsideal_yy/zygh/training/rules/getTypeQuestionCountList', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}




/** 21 查询题型分数 */
export async function queryQuestionTypeScore(
  params: {
    rules_id: number
  },
  options?: Record<string, any>,
) {
  return request<any>('/dsideal_yy/zygh/training/rules/getQuestionTypeScore', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}
