import { HttpClient } from '../http-client'; import type { BaseResponse } from '../types/common'; import type { DeviceRegisterRequest, DeviceResponse, DeviceSearchRequest, DeviceSearchResponse, DeviceUpdateRequest } from '../types/device.types'; function normalizePageable(params: DeviceSearchRequest): DeviceSearchRequest { return { ...params, pageable: { pageNumber: params.pageable?.pageNumber ?? 0, pageSize: params.pageable?.pageSize ?? 20, sort: params.pageable?.sort ?? { orders: [] } } }; } class DeviceService { private http: HttpClient; constructor(http: HttpClient) { this.http = http; } async register(data: DeviceRegisterRequest): Promise { return this.http.requestAndValidate('/devices/register', { method: 'POST', body: data }); } async getByCode(code: string): Promise { return this.http.requestAndValidate('/devices/by-code', { method: 'POST', body: { code } }); } async getById(deviceId: string): Promise { return this.http.requestAndValidate('/devices/by-id', { method: 'POST', body: { deviceId } }); } async update(data: DeviceUpdateRequest): Promise { return this.http.requestAndValidate('/devices', { method: 'PATCH', body: data }); } async search(params: DeviceSearchRequest = {}): Promise { return this.http.requestAndValidate('/devices/search', { method: 'POST', body: normalizePageable(params) }); } async delete(deviceId: string): Promise { return this.http.requestAndValidate('/devices', { method: 'DELETE', body: { deviceId } }); } } export { DeviceService };