import { HttpClient } from '../http-client'; import type { BaseResponse } from '../types/common'; import type { ProjectImportRequest, ProjectRegisterRequest, ProjectRegisterResponse, ProjectResponse, ProjectSearchRequest, ProjectSearchResponse, ProjectUpdateRequest } from '../types/project.types'; function normalizePageable(params: ProjectSearchRequest): ProjectSearchRequest { return { ...params, pageable: { pageNumber: params.pageable?.pageNumber ?? 0, pageSize: params.pageable?.pageSize ?? 20, sort: params.pageable?.sort ?? { orders: [] } } }; } class ProjectService { private http: HttpClient; constructor(http: HttpClient) { this.http = http; } async search(params: ProjectSearchRequest = {}): Promise { return this.http.requestAndValidate('/projects/search', { method: 'POST', body: normalizePageable(params) }); } async getById(projectId: string, tenantId?: string): Promise { return this.http.requestAndValidate('/projects/by-id', { method: 'POST', body: { projectId, tenantId } }); } async getByCode(code: string, tenantId?: string): Promise { return this.http.requestAndValidate('/projects/by-key', { method: 'POST', body: { code, tenantId } }); } async register(data: ProjectRegisterRequest): Promise { return this.http.requestAndValidate('/projects/register', { method: 'POST', body: data }); } async importProject(data: ProjectImportRequest): Promise { return this.http.requestAndValidate('/projects/import', { method: 'POST', body: data }); } async update(data: ProjectUpdateRequest): Promise { return this.http.requestAndValidate('/projects', { method: 'PATCH', body: data }); } async delete(projectId: string): Promise { return this.http.requestAndValidate('/projects', { method: 'DELETE', body: { projectId } }); } } export { ProjectService };