import { IFlightFactory } from '.';
import { IDirectFlight } from './contracts';
import { DirectFlight } from './flight.model';
import { IFlightStrategy } from './flight.strategy';

export class DirectFlightStrategy implements IFlightStrategy {
    getLegs(flight: DirectFlight) {
        return [flight.leg];
    }
    getFlights(flight: DirectFlight) {
        return [flight];
    }

    getFirstLeg(flight: DirectFlight) {
        return flight.leg;
    }
    getCurrentLeg(flight: DirectFlight) {
        return flight.leg;
    }
    getLastLeg(flight: DirectFlight) {
        return flight.leg;
    }

    getFirstFlight(flight: DirectFlight) {
        return flight;
    }
    getLastFlight(flight: DirectFlight) {
        return flight;
    }

    getFlightId(flight: DirectFlight) {
        return flight.flightId;
    }

    fromContract(contract: IDirectFlight, { createLeg }: IFlightFactory) {
        const leg = createLeg(contract.leg);

        const flight: Partial<DirectFlight> = {
            ...contract,
            leg,
        };

        return flight;
    }
}
