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);
};

// ============== 医院信息 ==============
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);
};
