import kcRequest from "@/service/request/index.js";

// ============== 服务工单 ==============
// 列表
export const getAdminOrders = (params) => {
  return kcRequest.request(`/admin/orders`, "get", params);
};
// 详情
export const getAdminOrderDetail = (id) => {
  return kcRequest.request(`/admin/orders/${id}`, "get");
};
// 提交工单（multipart/form-data，承载附件 files）
export const createAdminOrder = (formData) => {
  return kcRequest.uploadFile(`/admin/orders`, formData);
};
// 处理工单
export const processAdminOrder = (id, data) => {
  return kcRequest.request(`/admin/orders/${id}/process`, "put", data);
};
// 编辑工单（multipart/form-data，承载附件 files）
export const updateAdminOrder = (id, formData) => {
  return kcRequest.uploadFile(`/admin/orders/${id}`, formData, true, "PUT");
};
// 删除工单（软删除）
export const deleteAdminOrder = (id) => {
  return kcRequest.request(`/admin/orders/${id}`, "delete");
};

// ============== 医院信息 ==============
export const getAdminHospitals = (params) => {
  return kcRequest.request(`/admin/hospitals`, "get", params);
};
export const getAdminHospitalDetail = (id) => {
  return kcRequest.request(`/admin/hospitals/${id}`, "get");
};
// 新增/编辑医院：使用 multipart/form-data，承载表单字段与验收报告 file[]
export const createAdminHospital = (formData) => {
  return kcRequest.uploadFile(`/admin/hospitals`, formData);
};
export const updateAdminHospital = (id, formData) => {
  return kcRequest.uploadFile(`/admin/hospitals/${id}`, formData, true, "PUT");
};

// ============== 通用文件 ==============
// 下载/预览上传的文件（医院验收报告等），GET，返回 Blob
export const getUploadFile = (fileName) => {
  return kcRequest.downloadFile(`/upload/${fileName}`);
};

// ============== 账号管理 ==============
export const getAdminAccounts = (params) => {
  return kcRequest.request(`/admin/accounts`, "get", params);
};
export const createAdminAccount = (data) => {
  return kcRequest.request(`/admin/accounts`, "post", data);
};
export const updateAdminAccount = (id, data) => {
  return kcRequest.request(`/admin/accounts/${id}`, "put", data);
};
export const toggleAdminAccountStatus = (id) => {
  return kcRequest.request(`/admin/accounts/${id}/status`, "put");
};
export const resetAdminAccountPassword = (id) => {
  return kcRequest.request(`/admin/accounts/${id}/reset-password`, "post");
};

// 当前登录用户修改自己的密码（401 = 旧密码错误，使用 silent 避免误跳登录页）
export const changeMyPassword = (data) => {
  return kcRequest.request(`/admin/accounts/change-password`, "put", data, true, "json", true);
};

// ============== 服务报告 ==============
// 报告列表
export const getAdminReports = (params) => {
  return kcRequest.request(`/admin/reports`, "get", params);
};
// 报告详情
export const getAdminReportDetail = (id) => {
  return kcRequest.request(`/admin/reports/${id}`, "get");
};
// 生成报告
export const generateAdminReport = (data) => {
  return kcRequest.request(`/admin/reports/generate`, "post", data);
};
// 更新备注
export const updateAdminReportRemark = (id, data) => {
  return kcRequest.request(`/admin/reports/${id}/remark`, "put", data);
};
// 切换发送状态
export const toggleAdminReportSendStatus = (id) => {
  return kcRequest.request(`/admin/reports/${id}/send-status`, "put");
};
// 下载报告文件（返回 Blob）
export const downloadAdminReport = (id, format) => {
  return kcRequest.downloadFile(`/admin/reports/${id}/download?format=${format}`);
};

// ============== 客户服务（1.6） ==============
// 维保列表
export const getAdminMaintenance = (params) => {
  return kcRequest.request(`/admin/customer-service/maintenance`, "get", params);
};
// 维保详情
export const getAdminMaintenanceDetail = (hospitalId) => {
  return kcRequest.request(`/admin/customer-service/maintenance/${hospitalId}`, "get");
};
// 更新维保信息
export const updateAdminMaintenance = (hospitalId, data) => {
  return kcRequest.request(`/admin/customer-service/maintenance/${hospitalId}`, "put", data);
};
// 月视图数据
export const getAdminMonthlyView = (params) => {
  return kcRequest.request(`/admin/customer-service/monthly-view`, "get", params);
};
// 本月到期医院
export const getAdminExpiring = () => {
  return kcRequest.request(`/admin/customer-service/expiring`, "get");
};
// 电话回访记录
export const getAdminCalls = (hospitalId, params) => {
  return kcRequest.request(`/admin/customer-service/${hospitalId}/calls`, "get", params);
};
export const addAdminCall = (hospitalId, data) => {
  return kcRequest.request(`/admin/customer-service/${hospitalId}/calls`, "post", data);
};
// 现场巡检记录
export const getAdminInspections = (hospitalId) => {
  return kcRequest.request(`/admin/customer-service/${hospitalId}/inspections`, "get");
};
export const addAdminInspection = (hospitalId, data) => {
  // 新增现场巡检：multipart/form-data，承载表单字段与巡检报告 files[]
  return kcRequest.uploadFile(`/admin/customer-service/${hospitalId}/inspections`, data);
};
// 培训记录
export const getAdminTrainings = (hospitalId) => {
  return kcRequest.request(`/admin/customer-service/${hospitalId}/trainings`, "get");
};
export const addAdminTraining = (hospitalId, data) => {
  return kcRequest.request(`/admin/customer-service/${hospitalId}/trainings`, "post", data);
};
// 纪念品记录
export const getAdminGifts = (hospitalId) => {
  return kcRequest.request(`/admin/customer-service/${hospitalId}/gifts`, "get");
};
export const addAdminGift = (hospitalId, data) => {
  return kcRequest.request(`/admin/customer-service/${hospitalId}/gifts`, "post", data);
};

// ============== 客户经理积分（1.7） ==============
// 积分统计
export const getManagerPointsStats = (params) => {
  return kcRequest.request(`/admin/manager-points/stats`, "get", params);
};
// 积分排行榜
export const getManagerPointsLeaderboard = (params) => {
  return kcRequest.request(`/admin/manager-points/leaderboard`, "get", params);
};
// 积分规则
export const getManagerPointsRules = () => {
  return kcRequest.request(`/admin/manager-points/rules`, "get");
};
// 客户经理积分明细
export const getManagerPointsDetails = (managerId, params) => {
  return kcRequest.request(`/admin/manager-points/${managerId}/details`, "get", params);
};
// 手动调整积分
export const awardManagerPoints = (data) => {
  return kcRequest.request(`/admin/manager-points/award`, "post", data);
};
