import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs';
import { apiUriJean, apiUriMathew } from 'src/environments/environment';


@Injectable({
  providedIn: 'root'
})
export class HttpRequestService {

  private _url:string;
  private _token:string;

  constructor(private _http: HttpClient) {
    this._url = `${apiUriMathew}`;
    this._token = `Bearer ${localStorage.getItem('token')}`;
  }

  public getQuery(query: string) {
    const URL = `${this._url}/${query}/`;
    return this._http.get(URL, {
      headers: new HttpHeaders({
        Authorization: this._token,
      }),
    });
  }

  public postQuery(query: string, body: any) {
    const URL = `${this._url}/${query}`;
    return this._http.post(URL, body, {
      headers: new HttpHeaders({
        Authorization: this._token,
      }),
    });
  }

  public putQuery(query: string, body: any) {
    const URL = `${this._url}/${query}/`;
    return this._http.put(URL, body, {
      headers: new HttpHeaders({
        Authorization: this._token,
      }),
    });
  }

}
