import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {CookieService} from "ngx-cookie";
import {AppConfigService} from "@webbpm/base-package";

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

  constructor(private http: HttpClient,
              private cookieService: CookieService,
              private appConfigService: AppConfigService) {
  }

  checkAuthentication(): Promise<any>{
    return this.appConfigService.load().then(() => this.http.get<any>("version").toPromise())
  }

  logout(): Promise<string> {
    return this.http.post<string>('esia/logout', {}).toPromise();
  }

  public isAuthenticated(): boolean {
    return this.cookieService.get('webbpm.ervu-lkrp-fl') != null;
  }
}
