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

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

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

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

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

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

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

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