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

const prefix = 'china-medicine/';

/**
 * 分页查询用户列表
 * @param data
 */
export async function getChinaMedicineList(data: any) {
  return requestClient.get<any>(`${prefix}list`, { params: data });
}

/**
 * 分页查询用户列表
 * @param data
 */
export async function getChinaMedicineOption(data: any) {
  return requestClient.get<any>(`${prefix}option`, { params: data });
}

/**
 * 获取中药详情
 * @param id
 */
export async function getChinaMedicineInfo(id: number) {
  return requestClient.get<any>(`${prefix}detail`, { params: { id } });
}

/**
 * 导出中药药品
 */
export async function exportChinaMedicineApi() {
  return requestClient.download(`${prefix}export`);
}

/**
 * 新增中药
 * @param data
 */
export async function createChinaMedicine(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}create`, data);
}

/**
 * 编辑中药
 * @param data
 */
export async function updateChinaMedicine(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}update`, data);
}

/**
 * 删除中药
 * @param data
 */
export async function deleteChinaMedicine(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}delete`, data);
}

/**
 * 导入中药
 * @param data
 */
export async function importChinaMedicineApi(data: Record<string, any>) {
  return requestClient.upload(`${prefix}import`, data);
}

/**
 * 预览批量更新药品编码（只读）
 */
export async function previewBatchDrugNumberApi(data: {
  items: { drug_name: string; drug_number: string }[];
}) {
  return requestClient.post<any>(`${prefix}preview-batch-drug-number`, data);
}

/**
 * 批量更新编码：全量中药 id/名称/编号（卡片参考）
 */
export async function getAllDrugNumbersForBatchApi() {
  return requestClient.get<{
    items: {
      id: number;
      drug_name: string;
      drug_number: null | string;
      pinyin_simple: string;
    }[];
  }>(`${prefix}list-all-drug-numbers-for-batch`);
}

/**
 * 确认批量更新药品编码
 */
export async function applyBatchDrugNumberApi(data: {
  items: { id: number; drug_number: string }[];
}) {
  return requestClient.post<any>(`${prefix}apply-batch-drug-number`, data);
}

/**
 * 同步空拼音（首拼/全拼/数字串）
 */
export async function syncChinaMedicinePinyin() {
  return requestClient.post<any>(`${prefix}sync-pinyin`, {});
}
