import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';

@Injectable({
  providedIn: 'root'
})

export class API {
  constructor(private http: HttpClient) {
  }
  private headers = {
    'Content-Type': 'application/json; charset=utf-8',
    // 'LoggedInUser': sessionStorage.getItem('userId') 
  };
  //  Extranet API Base Url
  Post(url, obj) {
    return this.http.post<any>(environment.ExtranetAPIBaseUrl + url, obj,
      { headers: this.headers }
    );
  }

  Put(url, obj) {
    return this.http.put<any>(environment.ExtranetAPIBaseUrl + url, obj,
      { headers: this.headers }
    );
  }

  Delete(url) {
    return this.http.delete<any>(environment.ExtranetAPIBaseUrl + url,
      { headers: this.headers }
    );
  }

  Get(url) {
    return this.http.get<any>(environment.ExtranetAPIBaseUrl + url,
      { headers: this.headers }
    );
  }
  //  Admin API Base Url
  AdminPost(url, obj) {
    return this.http.post<any>(environment.APIBaseUrl + url, obj,
      { headers: this.headers }
    );
  }

  AdminPut(url, obj) {
    return this.http.put<any>(environment.APIBaseUrl + url, obj,
      { headers: this.headers }
    );
  }

  AdminDelete(url) {
    return this.http.delete<any>(environment.APIBaseUrl + url,
      { headers: this.headers }
    );
  }

  AdminGet(url) {
    return this.http.get<any>(environment.APIBaseUrl + url,
      { headers: this.headers }
    );
  }
  //  admin api go
  AdminGoPost(url, obj) {
    return this.http.post<any>(environment.AdminAPIGOBaseUrl + url, obj,
      { headers: this.headers }
    );
  }

  AdminGOPut(url, obj) {
    return this.http.put<any>(environment.AdminAPIGOBaseUrl + url, obj,
      { headers: this.headers }
    );
  }

  AdminGODelete(url) {
    return this.http.delete<any>(environment.AdminAPIGOBaseUrl + url,
      { headers: this.headers }
    );
  }

  AdminGOGet(url) {
    return this.http.get<any>(environment.AdminAPIGOBaseUrl + url,
      { headers: this.headers }
    );
  }
  // 
  PostFile(url, obj) {
    return this.http.post<any>(environment.APIBaseUrl + url, obj,);
  }

  PostFileExtranet(url, obj){
    return this.http.post<any>(environment.ExtranetAPIBaseUrl + url, obj,);
  }

    //Admin API GO
    PostGo(url, obj, customHeaders = null) {
      let postHeaders = JSON.parse(JSON.stringify(this.headers))
      if (customHeaders != null) {
        postHeaders = { ...postHeaders, ...customHeaders }
      }
      return this.http.post<any>(environment.APIBaseGoUrl + url, obj,
        { headers: postHeaders }
      );
    }
  
    GetGo(url) {
      return this.http.get<any>(environment.APIBaseGoUrl + url,
        { headers: this.headers }
      );
    }
  
    PostFileGo(url, obj) {
      return this.http.post<any>(environment.APIBaseGoUrl + url, obj,);
    }
    getAdjustedLocalTime(): number {
      const calculatedTime = sessionStorage.getItem('UGT') || '0';
      const localTime = new Date().getTime();
      return localTime + parseInt(calculatedTime);
  }
}

