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

export async function queryFakeList(params: {
  count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/api/card_fake_list', {
    params,
  });
}

/**
 * 获取题型
 * @param params 
 * @returns 
 */
 export async function queryQuestionType(): Promise<{ list: any } > {
  return request('/dsideal_yy/newUniversityExamination/base/getDicItem', {
    method: 'GET',
    params: {
      kind: 'ZYGH_TRAINING_QUESTION_TYPE'
    },    
  });  
}

/**
 * 下载模板
 * @param params 
 * @returns 
 */
 export async function exportQuestionTemplate(): Promise<{ list: any } > {
  return request('/dsideal_yy/zygh/training/exportQuestionTemplate', {
    method: 'GET',
    params: {
      
    },    
  });  
}

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

/**
 * 获取试题列表
 * @param params 
 * @returns 
 */
export async function queryQuestionList(params: {
  count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/dsideal_yy/zygh/training/getQuestionList', {
    params,
  });
}

/**
 * 获取试题详情
 * @param params 
 * @returns 
 */
export async function queryQuestionById(params: {
  id: number;
}): Promise<{ bean: any }> {
  return request('/dsideal_yy/zygh/training/getQuestionById', {
    params,
  });
}

/** 删除试题 */
export async function removeQuestion(data: { key: number[] }, options?: Record<string, any>) {
  console.log('data:::', data);
  const ids = [];
  data.key?.forEach((value)=>{
    ids.push({id: value})
  })

  return request<Record<string, any>>('/dsideal_yy/zygh/training/delQuestion', {
    data: { ids: JSON.stringify(ids) }, // 当前接口支持批量操作
    method: 'POST',
    requestType: 'form',
    ...(options || {}),
  });
}