import { http } from '@/utils/http/axios';
import type { QueryPageRequest, QueryPageResponse } from '@/types/basic-query';

/**
 * 劳防用品领用管理 - 实体与接口
 * 基础路径: /api/personalProtectiveEquipmentReceive
 */

/** 劳防用品领用记录实体 */
export interface PersonalProtectiveEquipmentReceive {
  id?: number; // 领用记录唯一ID（自增）
  equipmentId?: string | number; // 劳防用品ID
  version?: string; // 型号
  ppeName?: string; // 防护用品名称
  hazardFactor?: string; // 职业危害因素
  issuerCode?: string; // 发放人CODE
  issuerName?: string; // 发放人名称
  issueTime?: string; // 发放时间
  receiveNum?: number | string; // 领用数量
  receiverCode?: string; // 领用人CODE
  receiverName?: string; // 领用人名称
  remark?: string; // 领用备注
  status?: number | string; // 用品状态：1-启用，0-禁用
  isDeleted?: string | number;
  createdAt?: string;
  updatedAt?: string;
}

/** 分页查询请求 - 查询条件 */
export interface QueryPersonalProtectiveEquipmentReceivePageReq {
  name?: string; // 标题
  status?: number | string; // 状态：1-启用，0-禁用
}

/** 分页查询劳防用品领用列表 */
export function queryPersonalProtectiveEquipmentReceiveList(
  query: QueryPageRequest<QueryPersonalProtectiveEquipmentReceivePageReq>,
) {
  return http.request<QueryPageResponse<PersonalProtectiveEquipmentReceive>>({
    url: '/personalProtectiveEquipmentReceive/queryPersonalProtectiveEquipmentReceiveList',
    method: 'post',
    data: query,
  });
}

/** 新增劳防用品领用（id 不传） */
export function savePersonalProtectiveEquipmentReceive(
  data: PersonalProtectiveEquipmentReceive,
) {
  return http.request({
    url: '/personalProtectiveEquipmentReceive/savePersonalProtectiveEquipmentReceive',
    method: 'post',
    data,
  });
}

/** 编辑劳防用品领用（id 必传） */
export function updatePersonalProtectiveEquipmentReceive(
  data: PersonalProtectiveEquipmentReceive,
) {
  return http.request({
    url: '/personalProtectiveEquipmentReceive/updatePersonalProtectiveEquipmentReceive',
    method: 'put',
    data,
  });
}

/** 查询劳防用品领用详情（id 必传，RequestParam） */
export function queryPersonalProtectiveEquipmentReceiveDetail(id: number) {
  return http.request<PersonalProtectiveEquipmentReceive>({
    url: `/personalProtectiveEquipmentReceive/queryPersonalProtectiveEquipmentReceiveDetail?id=${id}`,
    method: 'post',
  });
}

/** 删除劳防用品领用（POST，传 id） */
export function deletePersonalProtectiveEquipmentReceive(id: number) {
  return http.request({
    url: `/personalProtectiveEquipmentReceive/deletePersonalProtectiveEquipmentReceive?id=${id}`,
    method: 'delete',
  });
}

/**
 * 导出劳防用品领用管理
 * @returns Promise<any> 导出的劳防用品领用管理
 */
export function exportPersonalProtectiveEquipmentReceiveList (queryParams) {
  return http.request({
    url: '/personalProtectiveEquipmentReceive/exportProtectiveEquipmentReceive',
    method: 'post',
    responseType: 'blob',
    data: queryParams,
  }, {
    isTransformResponse: false,
  });
}