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 CanActivateRouteSearch implements CanActivate {
    constructor(
        private urlService: OnlineBoardUrlParserService,
        private routeParamsService: CanActivateRouteParams,
    ) {}

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

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