import request from '@/utils/request';
import type { CreateProjectGroupRequest, UpdateProjectGroupRequest, ProjectGroup, ProjectGroupQueryParams } from './types';
import type { Page } from '@/types/base';

const BASE_URL = '/api/v1/project-group';

// 创建项目
export const createProjectGroup = (data: CreateProjectGroupRequest) =>
    request.post<void>(BASE_URL, data);

// 更新项目
export const updateProjectGroup = (data: UpdateProjectGroupRequest) =>
    request.put<void>(`${BASE_URL}/${data.id}`, data);

// 删除项目
export const deleteProjectGroup = (id: number) =>
    request.delete<void>(`${BASE_URL}/${id}`);

// 获取项目详情
export const getProjectGroup = (id: number) =>
    request.get<ProjectGroup>(`${BASE_URL}/${id}`);

// 分页查询项目列表
export const getProjectGroupPage = (params?: ProjectGroupQueryParams) =>
    request.get<Page<ProjectGroup>>(`${BASE_URL}/page`, { params });

// 获取所有项目列表
export const getProjectGroupList = () =>
    request.get<ProjectGroup[]>(BASE_URL);

// 条件查询项目列表
export const getProjectGroupListByCondition = (params?: ProjectGroupQueryParams) =>
    request.get<ProjectGroup[]>(`${BASE_URL}/list`, { params });

// 批量处理项目
export const batchProcessProjectGroup = (data: any) =>
    request.post<void>(`${BASE_URL}/batch`, data);

// 导出项目数据
export const exportProjectGroup = () =>
    request.get(`${BASE_URL}/export`, { responseType: 'blob' });
