import { HttpClient } from '../http-client'; import type { BaseResponse } from '../types/common'; import type { TenantImportRequest, TenantRegisterRequest, TenantRegisterResponse, TenantResponse, TenantSearchRequest, TenantSearchResponse, TenantUpdateRequest } from '../types/tenant.types'; function normalizePageable(params: TenantSearchRequest): TenantSearchRequest { return { ...params, pageable: { pageNumber: params.pageable?.pageNumber ?? 0, pageSize: params.pageable?.pageSize ?? 20, sort: params.pageable?.sort ?? { orders: [] } } }; } class TenantService { private http: HttpClient; constructor(http: HttpClient) { this.http = http; } async search(params: TenantSearchRequest = {}): Promise { return this.http.requestAndValidate('/tenants/search', { method: 'POST', body: normalizePageable(params) }); } async getById(tenantId: string): Promise { return this.http.requestAndValidate('/tenants/by-id', { method: 'POST', body: { tenantId } }); } async getByCode(code: string): Promise { return this.http.requestAndValidate('/tenants/by-key', { method: 'POST', body: { code } }); } async register(data: TenantRegisterRequest): Promise { return this.http.requestAndValidate('/tenants/register', { method: 'POST', body: data }); } async importTenant(data: TenantImportRequest): Promise { return this.http.requestAndValidate('/tenants/import', { method: 'POST', body: data }); } async update(data: TenantUpdateRequest): Promise { return this.http.requestAndValidate('/tenants', { method: 'PATCH', body: data }); } async delete(tenantId: string): Promise { return this.http.requestAndValidate('/tenants', { method: 'DELETE', body: { tenantId } }); } } export { TenantService };