import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate } from '@angular/router';
import { OnlineBoardUrlParserService } from '@online-board/services/url/url-parser.service';
import { CanActivateRouteParams } from './utils/can-activate-route-params';

@Injectable()
export class CanActivateDepartureSearch implements CanActivate {
    constructor(
        private urlService: OnlineBoardUrlParserService,
        private routeParamsService: CanActivateRouteParams,
    ) {}

    canActivate(route: ActivatedRouteSnapshot) {
        const urlParams = this.urlService.parseDepartureSearchUrlParams(
            route.params.params,
        );

        return this.routeParamsService.canActivate(urlParams);
    }
}
