import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders  } from "@angular/common/http";
import { Observable } from "rxjs";
const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
  providedIn: "root",
})
export class MasterService {
  loadDataIcon = null;
  apiBaseURL = 'assets/data';
  constructor(private http: HttpClient) {
    this.loadDataIcon = `${this.apiBaseURL}/hemat/remixicons.json`;
  }

  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 });
  }

  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 });
  }

  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 });
  }
  
  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 });
  }

  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 });
  }

  getIconData(): Observable<any> {
    return this.http.get(this.loadDataIcon, httpOptions);
  }
}
