import request from '@/utils/request';
import type { TaskDetailResponse } from '@/servers/types/supplierEvaluateTask';

/**
 * 获取所有模板列表
 * @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<TaskDetailResponse>(`/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.TaskAddRequest) {
  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 },
  });
}

/**
 * 获取评价结果列表
 * @param params 查询参数
 * @returns Promise
 */
export async function getEvaluateResultList(params: API.EvaluateTaskRequest) {
  return request<API.APIResponse<API.EvaluateTaskData>>('/coscoEvaluate/task/getTaskPage', {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取评价结果详情列表（供应商列表）
 * @param params 查询参数
 * @returns Promise
 */
export async function getEvaluateSupplierList(params: API.EvaluateSupplierRequest) {
  return request<API.APIResponse<API.EvaluateSupplierData>>('/coscoEvaluate/supplier/getPage', {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取供应商评价打分情况
 * @param params 查询参数
 * @returns Promise
 */
export async function getEvaluateScoreList(params: API.EvaluateScoreRequest) {
  return request<API.APIResponse<API.PageResponse<any>>>('/coscoEvaluate/supplier/getSupplierDimension', {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取评价打分详情
 * @param id 评价记录ID
 * @returns Promise
 */
export async function getEvaluateScoreDetail(id: string) {
  return request<API.APIResponse<API.EvaluateScoreDetailData>>(`/coscoEvaluate/user/getIndicator?id=${id}`, {
    method: 'GET',
  });
}

/**
 * 获取所有评价规则列表
 * @returns Promise
 */
export async function getAllEvaluateRules() {
  return request<API.EvaluateRuleResponse>('/coscoEvaluate/level/getAllList', {
    method: 'GET',
  });
}

/**
 * 获取评价规则详情
 * @param id 规则ID
 * @returns Promise
 */
export async function getEvaluateRuleDetail(id: string) {
  return request<API.EvaluateRuleDetailResponse>(`/coscoEvaluate/level/${id}`, {
    method: 'GET',
  });
}

/**
 * 新增评价规则
 * @param params 规则数据
 * @returns Promise
 */
export async function addEvaluateRule(params: API.EvaluateRuleAddRequest) {
  return request<API.APIResponse<any>>('/coscoEvaluate/level', {
    method: 'POST',
    data: params,
  });
}

/**
 * 更新评价规则
 * @param params 规则数据
 * @returns Promise
 */
export async function updateEvaluateRule(params: API.EvaluateRuleUpdateRequest) {
  return request<API.APIResponse<any>>('/coscoEvaluate/level', {
    method: 'PUT',
    data: params,
  });
}

/**
 * 删除评价规则
 * @param id 规则ID
 * @returns Promise
 */
export async function deleteEvaluateRule(id: string) {
  return request<API.APIResponse<any>>(`/coscoEvaluate/level/${id}`, {
    method: 'DELETE',
  });
}

/**
 * 获取供应商评价得分明细
 * @param id 评价记录ID
 * @returns Promise
 */
export async function getSupplierScoreDetail(id: string) {
  return request<API.APIResponse<API.EvaluateScoreDetailData>>(`/coscoEvaluate/supplier/getScoreResult`, {
    method: 'GET',
    params: { id }
  });
}

/**
 * 提交供应商评价得分
 * @param params 评价得分数据
 * @returns
 */
export async function submitEvaluateScore(params: any) {
  return request('/api/supplier/evaluate/score/submit', {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取评价打分详情
 * @param id 评价记录ID
 * @returns
 */
export async function getIndicator(id: string) {
  return request('/coscoEvaluate/user/getIndicator', {
    method: 'GET',
    params: { id },
  });
}
