import { Inject, Injectable } from '@angular/core';
import { IScheduleRouteDirectionParams } from '@schedule/services/url/types';
import { SCHEDULE_URL_BASE } from '@schedule/services/url/url-base';
import { ScheduleUrlBuilderService } from '@schedule/services/url/url-builder.service';

@Injectable()
export class ScheduleRequestBuilderService {
    private readonly mode = 'route';
    private readonly area;
    constructor(
        private urlBuilder: ScheduleUrlBuilderService,
        @Inject(SCHEDULE_URL_BASE) public urlBase,
    ) {
        this.area = urlBase;
    }

    buildRouteRequest(
        params: IScheduleRouteDirectionParams,
        returnParams?: IScheduleRouteDirectionParams,
    ) {
        const formattedParams = this.urlBuilder.formatRouteParams(params);

        if (returnParams) {
            const formattedReturnParams =
                this.urlBuilder.formatRouteParams(returnParams);

            return `${this.base}-${formattedParams}-${formattedReturnParams}`;
        }

        return `${this.base}-${formattedParams}`;
    }

    private get base() {
        return `${this.area}-${this.mode}`;
    }
}
