import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { ScheduleUrlParserService } from '@schedule/services/url/url-parser.service';
import { IScheduleUrlParams } from '@schedule/types';

@Injectable()
export class ScheduleSearchPageUrlParamsResolver
    implements Resolve<IScheduleUrlParams>
{
    constructor(private urlService: ScheduleUrlParserService) {}

    resolve(route: ActivatedRouteSnapshot): IScheduleUrlParams {
        const { params, returnParams } = route.params;

        return {
            route: {
                outbound: this.urlService.parseRouteParams(params),
                inbound:
                    returnParams &&
                    this.urlService.parseRouteParams(returnParams),
            },
        };
    }
}
