import request from '@/utils/request';
import type {
  TaskDetailResponse,
  TemplateRequest,
  TemplateResponse,
  TemplateDetailResponse,
  TemplateAddRequest,
  TemplateUpdateRequest,
  CategoryTreeResponse,
  TaskSearchParams,
  TaskResponse,
  EvaluateTaskRequest,
  EvaluateTaskData,
  EvaluateSupplierRequest,
  EvaluateSupplierData,
  EvaluateScoreRequest,
  EvaluateScoreDetailData,
  EvaluateRuleResponse,
  EvaluateRuleDetailResponse,
  EvaluateRuleAddRequest,
  EvaluateRuleUpdateRequest,
  TaskAddRequest,
} from '@/servers/dao/supplierEvaluateTask';
import  '@/servers/dao/supplierEvaluateScore.d.ts';
/**
 * 获取所有模板列表
 * @returns 所有模板列表
 */
export async function getAllTemplates() {
  return request('/coscoEvaluate/template/getAllList', {
    method: 'GET',
  });
}

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

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

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


/**
 * 更新评价模板
 * @param params 模板数据
 * @returns Promise
 */
export async function updateTemplate(params: 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<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: TaskSearchParams) {
  return request<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: TaskAddRequest) {
  return request<API.APIResponse<any>>('/coscoEvaluate/task/addTask', {
    method: 'POST',
    data: params,
  });
}


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

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

/**
 * 获取供应商评价打分情况
 * @param params 查询参数
 * @returns Promise
 */
export async function getEvaluateScoreList(params: 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<EvaluateScoreDetailData>>(`/coscoEvaluate/user/getIndicator?id=${id}`, {
    method: 'GET',
  });
}

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

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

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

/**
 * 更新评价规则
 * @param params 规则数据
 * @returns Promise
 */
export async function updateEvaluateRule(params: 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<supplierEvaluateScore.ScoreDetailResponse>(`/coscoEvaluate/user/getIndicator`, {
    method: 'GET',
    params: { id }
  });
}

/**
 * 保存评分数据
 * @param params 保存评分参数
 * @returns Promise
 */
export async function saveEvaluateScore(params: supplierEvaluateScore.ScoreSaveRequest) {
  return request<supplierEvaluateScore.ScoreSaveResponse>(`/coscoEvaluate/user/getScore`, {
    method: 'POST',
    data: params,
  });
}

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

/**
 * 获取供应商维度列表
 * @param params 查询参数
 * @returns Promise
 */
export async function getSupplierDimension(params: supplierEvaluateScore.SupplierDimensionRequest) {
  return request<supplierEvaluateScore.SupplierDimensionResponse>(`/coscoEvaluate/supplier/getSupplierDimension`, {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取任务列表
 * @param params 查询参数
 * @returns Promise
 */
export async function getTaskPage(params: supplierEvaluateScore.TaskPageRequest) {
  return request<supplierEvaluateScore.TaskPageResponse>(`/coscoEvaluate/task/getTaskPage`, {
    method: 'POST',
    data: params,
  });
}

/**
 * 导出供应商评价数据
 * @param evaluateTaskId 评价任务ID
 * @returns Promise
 */
export async function exportSupplierEvaluate(evaluateTaskId: string) {
  const params: supplierEvaluateScore.ExportRequest = { evaluateTaskId };
  return request(`/coscoEvaluate/supplier/export`, {
    method: 'GET',
    params,
    responseType: 'arrayBuffer',
    getResponse: false,
  });
}
