import { Injectable } from "@angular/core"; import { HttpClient, HttpHeaders } from "@angular/common/http"; import { Observable } from "rxjs"; const BASE_URL = 'https://kapi.absys.ninja/hemat'; @Injectable({ providedIn: "root", }) export class DeviceService { constructor(private http: HttpClient) {} getDeviceData(id, category, status): Observable { const endpoint = `/devices`; const params = new URLSearchParams({ page: "1", limit: "100", building_id: id }); if (category) { params.append("category_id", category); } if (status) { params.append("status_id", status); } const url = `${BASE_URL}${endpoint}?${params.toString()}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } getDeviceDataById(id): Observable { const endpoint = `/devices`; const params = new URLSearchParams({ page: "1", limit: "100", building_id: id }); const url = `${BASE_URL}${endpoint}?${params.toString()}`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } getDeviceLIst(): Observable { const endpoint = `/devices`; const url = `${BASE_URL}${endpoint}/list`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.get(url, { headers }); } getSyncDeviceData(): Observable { const endpoint = `/devices`; const url = `${BASE_URL}${endpoint}/Synchronization`; const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' }); return this.http.get(url, { headers }); } deviceSwitch(data): Observable { const endpoint = `/devices`; const url = `${BASE_URL}${endpoint}/device-switch`; const headers = new HttpHeaders({ "Content-Type": "application/json", "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", }); return this.http.post(url, data, { headers }); } getStreamUrl(id): Observable { const endpoint = `/devices`; const url = `${BASE_URL}${endpoint}/live-stream?device_id=${id}`; const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' }); return this.http.get(url, { headers }); } }