// @ts-ignore
/* eslint-disable */
import { request } from 'umi';
import { TableListItem } from '../option/data';
import type { CardListItemDataType } from './data.d';

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



/** 获取主题详情 */
export async function getSubjectInfo(
  params: {
    id?: number;
  },
  options?: Record<string, any>,
) {
  return request('/dsideal_yy/ypt/careerTraining/subject/getSubjectInfo', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 复制主题 POST /dsideal_yy/ypt/careerTraining/subject/copySubject */
export async function copySubject(data: { [key: string]: any }, options?: { [key: string]: any }) {
  return request<TableListItem>('/dsideal_yy/ypt/careerTraining/subject/copySubject', {
    data,
    method: 'POST',
    requestType: "form",
    ...(options || {}),
  });
}





// /** 新建规则 PUT /api/rule */
// export async function updateRule(data: { [key: string]: any }, options?: { [key: string]: any }) {
//   return request<TableListItem>('/api/rule', {
//     data,
//     method: 'PUT',
//     ...(options || {}),
//   });
// }

// /** 新建规则 POST /api/rule */
// export async function addRule(data: { [key: string]: any }, options?: { [key: string]: any }) {
//   return request<TableListItem>('/api/rule', {
//     data,
//     method: 'POST',
//     ...(options || {}),
//   });
// }

// /** 删除规则 DELETE /api/rule */
// export async function removeRule(data: { key: number[] }, options?: { [key: string]: any }) {
//   return request<Record<string, any>>('/api/rule', {
//     data,
//     method: 'DELETE',
//     ...(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,
  });
}

/**
 * 根据主题获取章节列表
 * http://10.10.14.252:8080/workspace/myWorkspace.do?projectId=382#6428
 * @param params
 * @returns
 */
 export async function queryListChapterBySubject(params: {
  page_number: number;	//页码	number	非必填；默认为1
  page_size: number; // 每页条数	number	非必填；默认为10
  subject_id:	number; //主题id
  //count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> {
  return request('/dsideal_yy/ypt/careerTraining/subject/listChapterBySubject', {
    params,
  });
}

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

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

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


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


/** 获取章节详情 */
export async function getChapterAndCourseList(
  params: {
    id?: number;
  },
  options?: Record<string, any>,
) {
  return request('/dsideal_yy/ypt/careerTraining/subject/getChapterAndCourseList', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}
