import { CanActivateFn, Router } from '@angular/router';
import { inject } from '@angular/core';
import { AuthFacade } from '../../../adapters/authentification/auth.facade';

export const authGuard: CanActivateFn = (route, state) => {
  const authFacade = inject(AuthFacade);
  const router = inject(Router);

  authFacade.verifyEmail();
  authFacade.verifyAuthenticatedUser();

  if (!authFacade.isAuthenticated() || !authFacade.isEmailVerified()) {
    return router.parseUrl('/auth');
  }
  return true;
};
