import {Injectable} from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import {PackageService} from './package.service';

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

  constructor(private packageService: PackageService) { }

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    return route.data && route.data.package && this.hasPackageForRoute(route.data.package);
  }

  private hasPackageForRoute(packageId: string): boolean {
    return this.packageService.hasPackage(packageId);
  }
}
