import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from '@shared/auth/auth.service';
import { ConfigService } from '@shared/config/config.service';

@Injectable({
  providedIn: 'root'
})
export class CurrentUserResolver  {
  constructor(private authService: AuthService, private config: ConfigService) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
    if (route.params.activeClientId) {
      this.config.setActiveClientId(route.params.activeClientId);
    }
    return this.authService.checkIfLoggedIn(true);
  }
}
