import { request, type RequestOptions } from '@/utils/request';

/** 获取原材料出入库记录列表 GET /api/materials-in-out */
export async function materialsInOutList(
  params: API.MaterialsInOutListParams,
  options?: RequestOptions,
) {
  return request<{
    items?: API.MaterialsInOutEntity[];
    meta?: {
      itemCount?: number;
      totalItems?: number;
      itemsPerPage?: number;
      totalPages?: number;
      currentPage?: number;
    };
  }>('/api/materials-in-out', {
    method: 'GET',
    params: {
      // page has a default value: 1
      page: '1',
      // pageSize has a default value: 10
      pageSize: '10',

      ...params,
    },
    ...(options || {}),
  });
}

/** 新增原材料出入库记录 POST /api/materials-in-out */
export async function materialsInOutCreate(
  body: API.MaterialsInOutDto,
  options?: RequestOptions,
) {
  return request<any>('/api/materials-in-out', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || { successMsg: '创建成功' }),
  });
}

/** 获取原材料出入库记录信息 GET /api/materials-in-out/${param0} */
export async function materialsInOutInfo(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.MaterialsInOutInfoParams,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<API.MaterialsInOutEntity>(`/api/materials-in-out/${param0}`, {
    method: 'GET',
    params: { ...queryParams },
    ...(options || {}),
  });
}

/** 解除原材料出入库记录和附件关联 PUT /api/materials-in-out/unlink-attachments/${param0} */
export async function unlinkAttachments(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.MaterialsInOutUpdateParams, 
  body: API.MaterialsInOutUpdateDto,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<any>(`/api/materials-in-out/unlink-attachments/${param0}`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    params: { ...queryParams },
    data: body,
    ...options,
  });
}

/** 更新原材料出入库记录 PUT /api/materials-in-out/${param0} */
export async function materialsInOutUpdate(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.MaterialsInOutUpdateParams,
  body: API.MaterialsInOutUpdateDto,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<any>(`/api/materials-in-out/${param0}`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    params: { ...queryParams },
    data: body,
    ...(options || { successMsg: '更新成功' }),
  });
}

/** 删除原材料出入库记录 DELETE /api/materials-in-out/${param0} */
export async function materialsInOutDelete(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.MaterialsInOutDeleteParams,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<any>(`/api/materials-in-out/${param0}`, {
    method: 'DELETE',
    params: { ...queryParams },
    ...(options || { successMsg: '删除成功' }),
  });
}
