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

/** 获取课程列表 GET /dsideal_yy/ypt/careerTraining/course/list */
export async function queryCourseList(
  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/course/list', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 获取课程列表(不分页) GET /dsideal_yy/ypt/careerTraining/course/list */
export async function queryCourseListByTag(
  params: {
    tag_ids?: string; // 过滤标签
  },
  options?: Record<string, any>,
) {
  return request<{
    data: TableListItem[];
    /** 列表的内容总数 */
    total_row?: number;
    /** 页面的容量 */
    page_size?: number;
    success?: boolean;
  }>('/dsideal_yy/ypt/careerTraining/component/listCourseByTag', {
    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,
  });
}

export async function viewCourse(params: {
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request(' /dsideal_yy/ypt/careerTraining/course/view', {
    params,
  });
}



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

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

/** 查看课程（仅仅获取课程详情，不标记浏览量）GET /dsideal_yy/ypt/careerTraining/course/view */
export async function queryCourseView(params: {
  course_id: number;
  //count: number;
}): Promise<{ data: { list: any } }> {
  return request('/dsideal_yy/ypt/careerTraining/course/view', {
    params,
  });
}



/** 新建/修改主题 POST /dsideal_yy/ypt/careerTraining/subject/saveSubject */
export async function saveSubject(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>('/dsideal_yy/ypt/careerTraining/subject/saveSubject', {
    data,
    method: 'POST',
    requestType: 'form',
    ...(options || {}),
  });
}








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

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

/** 删除标签 /dsideal_yy/ypt/careerTraining/tag/delete**/
export async function deleteTag(data: Record<string, any>, options?: Record<string, any>) {
  return request<TableListItem>(' /dsideal_yy/ypt/careerTraining/tag/delete', {
    data,
    method: 'POST',
    requestType: 'form',
    ...(options || {}),
  });
}
