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



/** 获取产品列表 GET /api/product */
export async function productList(params: API.ProductParams, options?: RequestOptions) {
  return request<{
    items?: API.ProductEntity[];
    meta?: {
      itemCount?: number;
      totalItems?: number;
      itemsPerPage?: number;
      totalPages?: number;
      currentPage?: number;
    };
  }>('/api/product', {
    method: 'GET',
    params: {
      // page has a default value: 1
      page: '1',
      // pageSize has a default value: 10
      pageSize: '10',

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

/** 新增产品 POST /api/product */
export async function productCreate(body: API.ProductDto, options?: RequestOptions) {
  return request<any>('/api/product', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || { successMsg: '创建成功' }),
  });
}

/** 获取产品信息 GET /api/product/${param0} */
export async function productInfo(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.ProductInfoParams,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<API.ProductEntity>(`/api/product/${param0}`, {
    method: 'GET',
    params: { ...queryParams },
    ...(options || {}),
  });
}

/** 解除产品和附件关联 PUT /api/product/unlink-attachments/${param0} */
export async function unlinkAttachments(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.ProductUpdateParams,
  body: API.ProductUpdateDto,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<any>(`/api/product/unlink-attachments/${param0}`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    params: { ...queryParams },
    data: body,
    ...options,
  });
}

/** 更新产品 PUT /api/product/${param0} */
export async function productUpdate(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.ProductUpdateParams,
  body: API.ProductUpdateDto,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<any>(`/api/product/${param0}`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    params: { ...queryParams },
    data: body,
    ...(options || { successMsg: '更新成功' }),
  });
}

/** 删除产品 DELETE /api/product/${param0} */
export async function productDelete(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.ProductDeleteParams,
  options?: RequestOptions,
) {
  const { id: param0, ...queryParams } = params;
  return request<any>(`/api/product/${param0}`, {
    method: 'DELETE',
    params: { ...queryParams },
    ...(options || { successMsg: '删除成功' }),
  });
}
