import type { EmergencyInfoModel } from './model';

import type { BaseResult } from '#/api/base-result';

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

// API路径常量枚举
enum Api {
  // 导出
  export = '/sysEmergencyProtection/protection/export',
  // 列表查询
  list = '/sysEmergencyProtection/protection/list',
  // 基础路径
  root = '/sysEmergencyProtection/protection',
  // 所有用品列表
  all = '/sysEmergencyProtection/protection/all',
}

export function emergencyInfoAll() {
  return requestClient.get<BaseResult<EmergencyInfoModel[]>>(Api.all);
}

/**
 * 查询应急防护用品列表
 * @param params 查询参数
 * @returns 分页结果
 */
export function emergencyInfoList(params: any) {
  return requestClient.get<BaseResult<EmergencyInfoModel[]>>(Api.list, {
    params,
  });
}

/**
 * 获取应急防护用品详细信息
 * @param id 应急防护用品ID
 * @returns 应急防护用品详情
 */
export function getEmergencyInfoDetail(id: number) {
  return requestClient.get<EmergencyInfoModel>(`${Api.root}/${id}`);
}

/**
 * 新增应急防护用品
 * @param data 应急防护用品数据
 * @returns 操作结果
 */
export function addEmergencyInfo(data: EmergencyInfoModel) {
  return requestClient.post(Api.root, data, {
    successMessageMode: 'message',
  });
}

/**
 * 修改应急防护用品
 * @param data 应急防护用品数据
 * @returns 操作结果
 */
export function updateEmergencyInfo(data: EmergencyInfoModel) {
  return requestClient.put(Api.root, data, {
    successMessageMode: 'message',
  });
}

/**
 * 删除应急防护用品
 * @param ids 应急防护用品ID数组
 * @returns 操作结果
 */
export function deleteEmergencyInfo(ids: number[]) {
  return requestClient.delete(`${Api.root}/${ids.join(',')}`, {
    successMessageMode: 'message',
  });
}

/**
 * 导出应急防护用品列表
 * @param data 导出参数
 * @returns 导出结果
 */
export function exportEmergencyInfo(data: Partial<EmergencyInfoModel>) {
  return commonExport(Api.export, data);
}
