import type { ParamsType } from '@ant-design/pro-table/node_modules/@ant-design/pro-provider';
import { request } from 'umi';
import type { TableListItem } from './data';

/** 获取课程列表 GET /dsideal_yy/ypt/careerTraining/train/list */
export async function queryTrainList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total_row?: number;
    /** 页面的容量 */
    page_size?: number;
    success?: boolean;
  }>('/dsideal_yy/ypt/careerTraining/train/list', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 新建/修改课程 POST /dsideal_yy/ypt/careerTraining/train/save */
export async function saveTrain(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/ypt/careerTraining/train/save', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}

/** 删除课程 POST /dsideal_yy/ypt/careerTraining/train/delete */
export async function removeTrain(data: { key: number[] }, options?: Record<string, any>) {
  console.log('data:::', data);
  return request<Record<string, any>>('/dsideal_yy/ypt/careerTraining/train/delete', {
    data: { train_id: data?.key[0] }, // 当前接口不支持批量操作
    method: 'POST',
    requestType: 'form',
    ...(options || {}),
  });
}

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

/** 获取机构树 GET /dsideal_yy/ypt/sys/org/getOrgTreeForOa?org_id=200051&org_type=2&school_type=1 */
export async function queryOrgTree(
  params: ParamsType,
): Promise<any> {
  return request('/dsideal_yy/ypt/sys/org/getOrgTreeForOa', {
    params,
  });
}

/** 获取机构树根id （平台配置全局）*/
export async function queryValueByKey(
  params: ParamsType,
): Promise<any> {
  return request('/dsideal_yy/golbal/getValueByKey?key=common.org.id', {
    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/component/listSubject', {
    params,
  });
}

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

/**
 * 获取省市区
 * http://10.10.14.252:8080/workspace/myWorkspace.do?projectId=382#6426
 * @param params 
 * @returns 
 */
 export async function getAsyncOrgTree(params: {
  page_size: number;
  //count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/dsideal_yy/org/getAsyncOrgTree', {
    params,
  });
}

/**
 * 获取学校
 * http://10.10.14.252:8080/workspace/myWorkspace.do?projectId=382#6426
 * @param params 
 * @returns 
 */
 export async function getOrgList(params: {
  org_id: number;
  org_type: number;
  //count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/dsideal_yy/intellioa/thirdlib/get_org_list', {
    params,
  });
}

/**
 * 获取学校列表
 * /dsideal_yy/ypt/sys/org/getEduUnitList
 * @param params
 * @returns
 */
 export async function getEduUnitList(params: {
  page_size: number;
  //count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/dsideal_yy/ypt/sys/org/getEduUnitList', {
    params,
  });
}