import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { ApplicationHttpRouts } from "../constants/http-routs";

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

  //user login
  public userLogin(employeeId: string, password: string) {
    console.log("Login route " + ApplicationHttpRouts.LOG_IN);

    return this.http.get<any>(ApplicationHttpRouts.LOG_IN, {
      headers: this.basicAuthCredentialsBuilder(employeeId, password),
      withCredentials: true,
      observe: "response",
    });
  }

  // what goes to the backend for auth ... is the same as postman's basic auth
  private basicAuthCredentialsBuilder(
    employeeOrUserId: string,
    password: string
  ): HttpHeaders {
    console.log(`username and password${employeeOrUserId} p = ${password}`);

    return new HttpHeaders().set(
      "Authorization",
      "basic " + window.btoa(employeeOrUserId + ":" + password)
    );
  }


  public pingLiveStatus(){
    return this.http.get<any>(ApplicationHttpRouts.PING,{
      withCredentials: true,
      observe: "response",
    })
  }
}
