import { TestBed } from '@angular/core/testing';
import { ScheduleRequestBuilderService } from '@schedule/services/request/request-builder.service';
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';

describe('ScheduleRequestBuilderService', () => {
    let service: ScheduleRequestBuilderService;

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                ScheduleRequestBuilderService,
                ScheduleUrlBuilderService,
                {
                    provide: SCHEDULE_URL_BASE,
                    useValue: 'schedule',
                },
            ],
        });

        service = TestBed.inject(ScheduleRequestBuilderService);
    });

    it('should return request for one way route without time range and connections', () => {
        const expected = 'schedule-route-NBC-KHV-20220307-20220313';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const request = service.buildRouteRequest(route);
        expect(request).toBe(expected);
    });

    it('should return request for one way route without connections', () => {
        const expected = 'schedule-route-NBC-KHV-20220307-20220313-06002200';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            timeFrom: '0600',
            timeTo: '2200',
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const request = service.buildRouteRequest(route);
        expect(request).toBe(expected);
    });

    it('should return request for one way route without time range', () => {
        const expected = 'schedule-route-NBC-KHV-20220307-20220313-C1';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            connections: 1,
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const request = service.buildRouteRequest(route);
        expect(request).toBe(expected);
    });

    it('should return request for one way route', () => {
        const expected = 'schedule-route-NBC-KHV-20220307-20220313-06002200-C1';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            connections: 1,
            timeFrom: '0600',
            timeTo: '2200',
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const request = service.buildRouteRequest(route);
        expect(request).toBe(expected);
    });

    it('should return request for two ways route without time range and connections', () => {
        const expected =
            'schedule-route-NBC-KHV-20220307-20220313-KHV-NBC-20220307-20220313';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const returnRoute: IScheduleRouteDirectionParams = {
            ...route,
            departure: 'KHV',
            arrival: 'NBC',
        };

        const request = service.buildRouteRequest(route, returnRoute);
        expect(request).toBe(expected);
    });

    it('should return request for two ways route without connections', () => {
        const expected =
            'schedule-route-NBC-KHV-20220307-20220313-06002200-KHV-NBC-20220307-20220313-06002200';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            timeFrom: '0600',
            timeTo: '2200',
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const returnRoute: IScheduleRouteDirectionParams = {
            ...route,
            departure: 'KHV',
            arrival: 'NBC',
        };

        const request = service.buildRouteRequest(route, returnRoute);
        expect(request).toBe(expected);
    });

    it('should return request for two ways route without time range', () => {
        const expected =
            'schedule-route-NBC-KHV-20220307-20220313-C1-KHV-NBC-20220307-20220313-C1';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            connections: 1,
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const returnRoute: IScheduleRouteDirectionParams = {
            ...route,
            departure: 'KHV',
            arrival: 'NBC',
        };

        const request = service.buildRouteRequest(route, returnRoute);
        expect(request).toBe(expected);
    });

    it('should return request for two ways route', () => {
        const expected =
            'schedule-route-NBC-KHV-20220307-20220313-06002200-C1-KHV-NBC-20220307-20220313-06002200-C1';
        const route: IScheduleRouteDirectionParams = {
            departure: 'NBC',
            arrival: 'KHV',
            connections: 1,
            timeFrom: '0600',
            timeTo: '2200',
            dateFrom: new Date(2022, 2, 7),
            dateTo: new Date(2022, 2, 13),
        };

        const returnRoute: IScheduleRouteDirectionParams = {
            ...route,
            departure: 'KHV',
            arrival: 'NBC',
        };

        const request = service.buildRouteRequest(route, returnRoute);
        expect(request).toBe(expected);
    });
});
