import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { RootNavigationService } from '@shared/services/navigation.service';
import { IFlight } from '@typings/flight/flight';
import { IScheduleRouteDirectionParams } from './url/types';
import { ScheduleUrlBuilderService } from './url/url-builder.service';

@Injectable()
export class ScheduleNavigationService extends RootNavigationService {
    constructor(
        protected router: Router,
        private urlBuilder: ScheduleUrlBuilderService,
    ) {
        super(router);
    }

    public toRoutePage(
        routeParams: IScheduleRouteDirectionParams,
        returnRouteParams?: IScheduleRouteDirectionParams,
    ) {
        const url = this.urlBuilder.getRoutePageUrl(
            routeParams,
            returnRouteParams,
        );

        return this.router.navigateByUrl(url);
    }

    public toStartPage() {
        const url = this.urlBuilder.getStartPageUrl();
        return this.router.navigateByUrl(url);
    }

    public toDetailsPage(flight: IFlight, request?: string, date?: Date) {
        const url = this.urlBuilder.getDetailsPageUrl(flight, date);

        return this.router.navigate([url], {
            queryParams: {
                request,
            },
        });
    }
}
