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

type ParamsType = {
  count?: number;
} & Partial<BasicListItemDataType>;


export async function queryFakeList(
  params: ParamsType,
): Promise<{ data: { list: BasicListItemDataType[] } }> {
  return request('/api/get_list', {
    params,
  });
}


/**
 * 获取主题列表
 * 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,
  });
}

export async function removeFakeList(
  params: ParamsType,
): Promise<{ data: { list: BasicListItemDataType[] } }> {
  return request('/api/post_fake_list', {
    method: 'POST',
    data: {
      ...params,
      method: 'delete',
    },
  });
}


export async function addFakeList(
  params: ParamsType,
): Promise<{ data: { list: BasicListItemDataType[] } }> {
  return request('/api/post_fake_list', {
    method: 'POST',
    data: {
      ...params,
      method: 'post',
    },
  });
}

export async function updateFakeList(
  params: ParamsType,
): Promise<{ data: { list: BasicListItemDataType[] } }> {
  return request('/api/post_fake_list', {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}

/** 删除考试规则 */
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 updateRules(
  params: ParamsType,
): Promise<{ data: { info: string, success: boolean } }> {
  return request('/dsideal_yy/zygh/training/rules/updateRules', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params,
    },
  });
}

/**
 * 获取组卷，查询试题临时表（当前选题列表）
 * http://10.10.14.252:8080/workspace/myWorkspace.do?projectId=382#6426
 * @param params 
 * @returns 
 */
export async function queryTempQuestionList(params: {
  paper_uuid: string; // paper_uuid参数不能为空
  page_size: number;
  page_number: number;
  //count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/dsideal_yy/zygh/training/rules/getTempQuestionList', {
    params,
  });
}

/**
 * 15 组卷，手动组卷保存临时表
 * @param params 
 * @returns 
 */
export async function manualPaper(
  params: ParamsType,
): Promise<{ data: { list: BasicListItemDataType[] } }> {
  return request('/dsideal_yy/zygh/training/rules/manualPaper', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params,
    },
  });
}

/**
 * 20 组卷，提交保存试卷
 * @param params 
 * @returns 
 */
 export async function updatePaper(
  params: ParamsType,
): Promise<{ data: { list: BasicListItemDataType[] } }> {
  return request('/dsideal_yy/zygh/training/rules/updatePaper', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params,
    },
  });
}

/**
 * 25 模拟组卷，自动组卷
 * @param params 
 * @returns 
 */
 export async function autoPaper(
  params: ParamsType,
): Promise<{ data: { list: BasicListItemDataType[] } }> {
  return request('/dsideal_yy/zygh/training/rules/autoPaper', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params,
    },
  });
}
