import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders  } from "@angular/common/http";
import { Observable } from "rxjs";

@Injectable({
  providedIn: "root",
})
export class BuildingService {
  constructor(private http: HttpClient) {}

  postLogin(data: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/users/login`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.post<any>(url, data, { headers });
  }

  listBuilding(): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/building/dashboard/list`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  listDevicePerBuilding(id): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/devices/aggregate/on?building_id=${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getBuildingData(page: number = 1, limit: number = 10): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/building?page=${page}&limit=${limit}`;
    // const headers = new HttpHeaders().set('Content-Type', 'application/json');
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getRoomByBuildingId(buildingId: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room-building/list/byIds?buildingId=${buildingId}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getDeviceData(page: number = 1, limit: number = 10): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/devices?page=${page}&limit=${limit}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getSyncDeviceData(page: number = 1, limit: number = 10): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/devices/Synchronization`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getDeviceById(deviceId: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/devices/${deviceId}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getMasterListData(): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/header-param/list`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getMasterData(page: number = 1, limit: number = 100): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/header-param?page=${page}&limit=${limit}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getMasterBuildingData(page: number = 1, limit: number = 100): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/building?page=${page}&limit=${limit}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getBuildingList(): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/building/list`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getListRoomData(): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room/list`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getMasterRoomData(page: number = 1, limit: number = 100): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room?page=${page}&limit=${limit}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  getCostManagement(page: number = 1, limit: number = 100, ): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/cost_management?page=${page}&limit=${limit}&building_id=4&periode=2024-06`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  postHeaderDetailParam(data: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/header-detail-param`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.post<any>(url, data, { headers });
  }
  putHeaderDetailParam(data: any, id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/header-detail-param/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.put<any>(url, data, { headers });
  }
  
  deleteHeaderDetailParam(id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/header-detail-param/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.delete<any>(url, { headers });
  }

  postMasterBuildingParam(data: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/building`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.post<any>(url, data, { headers });
  }
  putMasterBuildingParam(data: any, id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/building/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.put<any>(url, data, { headers });
  }

  deleteMasterBuildingParam(id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/building/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.delete<any>(url, { headers });
  }

  postMasterRoomParam(data: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.post<any>(url, data, { headers });
  }
  putMasterRoomParam(data: any, id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.put<any>(url, data, { headers });
  }

  postBatchBuilding(data: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room-building/post-batch/room`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.post<any>(url, data, { headers });
  }

  getBuildingRoomList(page: number = 1, limit: number = 100): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room-building?page=${page}&limit=${limit}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  puttBuildingRoom(data: any, id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room-building/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.put<any>(url, data, { headers });
  }

  putDevice(data: any, id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/devices/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.put<any>(url, data, { headers });
  }

  getRoomBuildingById(roomBuildingId: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room-building/${roomBuildingId}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.get<any>(url, { headers });
  }

  deleteRoomBuilding(id: any): Observable<any> {
    const url = `https://kapi.absys.ninja/hemat/room-building/${id}`;
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
    });
    return this.http.delete<any>(url, { headers });
  }
}
