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

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

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

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

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

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

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

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