import request from '@/utils/request';

/**
 * 获取所有模板列表
 * @returns 所有模板列表
 */
export async function getAllTemplates() {
  return request('/coscoEvaluate/template/getAllList', {
    method: 'GET',
  });
}

/**
 * 获取模板列表
 * @param params 查询参数
 * @returns Promise
 */
export async function getTemplateList(params: SupplierEvaluate.TemplateRequest) {
  return request<SupplierEvaluate.TemplateResponse>('/coscoEvaluate/template/getPage', {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取模板详情
 * @param id 模板ID
 * @returns Promise
 */
export async function getTemplateDetail(id: string) {
  return request<SupplierEvaluate.TemplateDetailResponse>(`/coscoEvaluate/template/${id}`, {
    method: 'GET',
  });
}

/**
 * 新增模板
 * @param params 模板数据
 * @returns Promise
 */
export async function addTemplate(params: SupplierEvaluate.TemplateAddRequest) {
  return request<API.APIResponse<any>>('/coscoEvaluate/template', {
    method: 'POST',
    data: params,
  });
}


/**
 * 更新评价模板
 * @param params 模板数据
 * @returns Promise
 */
export async function updateTemplate(params: SupplierEvaluate.TemplateUpdateRequest) {
  return request<API.APIResponse<any>>('/coscoEvaluate/template', {
    method: 'PUT',
    data: params,
  });
}

/**
 * 删除评价模板
 * @param id 模板ID
 * @returns Promise
 */
export async function deleteTemplate(id: string) {
  return request<API.APIResponse<any>>('/coscoEvaluate/template/delete', {
    method: 'POST',
    data: { id },
  });
}

/**
 * 启用评价模板
 * @param id 模板ID
 * @returns Promise
 */
export async function enableTemplate(id: string) {
  return request<API.APIResponse<any>>('/coscoEvaluate/template/enable', {
    method: 'POST',
    data: { id },
  });
}

/**
 * 禁用评价模板
 * @param id 模板ID
 * @returns Promise
 */
export async function disableTemplate(id: string) {
  return request<API.APIResponse<any>>('/coscoEvaluate/template/disable', {
    method: 'POST',
    data: { id },
  });
}

/**
 * 获取品类列表
 * @returns Promise
 */
export async function getCategoryList() {
  return request<API.APIResponse<any>>('/coscoEvaluate/category/list', {
    method: 'GET',
  });
}

/**
 * 获取品类树
 * @returns Promise
 */
export async function getCategoryTree() {
  return request<SupplierEvaluate.CategoryTreeResponse>('/cosco/category/categoryTree', {
    method: 'GET',
  });
}

/**
 * 获取部门列表
 * @returns Promise
 */
export async function getDepartmentList() {
  return request<API.APIResponse<any>>('/coscoEvaluate/dept/list', {
    method: 'GET',
  });
}

/**
 * 获取评价任务列表
 * @param params 查询参数
 * @returns Promise
 */
export async function getTaskList(params: SupplierEvaluate.TaskRequest) {
  return request<SupplierEvaluate.TaskResponse>('/coscoEvaluate/task/getPage', {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取评价任务详情
 * @param id 任务ID
 * @returns Promise
 */
export async function getTaskDetail(id: string) {
  return request<API.APIResponse<SupplierEvaluate.TaskRecord>>(`/coscoEvaluate/task/${id}`, {
    method: 'GET',
  });
}

/**
 * 新增评价任务
 * @param params 任务数据
 * @returns Promise
 */
export async function addTask(params: SupplierEvaluate.TaskAddRequest) {
  return request<API.APIResponse<any>>('/coscoEvaluate/task/addTask', {
    method: 'POST',
    data: params,
  });
}

/**
 * 更新评价任务
 * @param params 任务数据
 * @returns Promise
 */
export async function updateTask(params: SupplierEvaluate.TaskUpdateRequest) {
  return request<API.APIResponse<any>>('/coscoEvaluate/task', {
    method: 'PUT',
    data: params,
  });
}

/**
 * 删除评价任务
 * @param id 任务ID
 * @returns Promise
 */
export async function deleteTask(id: string) {
  return request<API.APIResponse<any>>('/coscoEvaluate/task/delete', {
    method: 'POST',
    data: { id },
  });
}

/**
 * 批量删除评价任务
 * @param ids 任务ID数组
 * @returns Promise
 */
export async function batchDeleteTask(ids: string[]) {
  return request<API.APIResponse<any>>('/coscoEvaluate/task/batchDelete', {
    method: 'POST',
    data: { ids },
  });
}
