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

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

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

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

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

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

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

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