import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { AuthenticationService } from '@msfa-services/api/authentication.service';

@Injectable({
  providedIn: 'root',
})
export class SkipIfLoggedInGuard implements CanActivate {
  constructor(private authenticationService: AuthenticationService, private router: Router) {}

  canActivate(): boolean {
    if (this.authenticationService.isLoggedInWithValidToken) {
      void this.router.navigateByUrl('/');
      return false;
    }

    return true;
  }
}
