import { requestClient } from '#/api/request';

const prefix = 'department/';

/**
 * 获取科室树形列表（平铺返回，前端 treeConfig transform 组树）
 * xk-api GET /department/list
 * @param data name 科室名称模糊搜索
 */
export async function getDepartmentList(data: any) {
  return requestClient.get<any>(`${prefix}list`, { params: data });
}

/**
 * 获取科室下拉选项（选择父级科室用，返回 [{id, name, pid, level}]）
 * xk-api GET /department/option
 */
export async function getDepartmentOption() {
  return requestClient.get<any>(`${prefix}option`);
}

/**
 * 新增科室（level 由后端按 pid 推导，最多两级）
 * xk-api POST /department/create
 */
export async function createDepartment(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}create`, data);
}

/**
 * 编辑科室
 * xk-api POST /department/update
 */
export async function updateDepartment(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}update`, data);
}

/**
 * 删除科室（物理删除，后端校验子科室与医生绑定）
 * xk-api POST /department/delete
 */
export async function deleteDepartment(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}delete`, data);
}
