import { IMultiFlight } from './contracts';
import { MultiLegFlight } from './flight.model';
import { IFlightFactory, IFlightStrategy } from './flight.strategy';
export class MultiLegFlightStrategy implements IFlightStrategy {
    getLegs(flight: MultiLegFlight) {
        return flight.legs;
    }
    getFlights(flight: MultiLegFlight) {
        return [flight];
    }

    getFirstLeg(flight: MultiLegFlight) {
        return flight.legs[0];
    }
    getCurrentLeg(flight: MultiLegFlight) {
        return flight.legs.find((l) => l.isCurrent) ?? flight.legs[0];
    }
    getLastLeg(flight: MultiLegFlight) {
        return flight.legs[flight.legs.length - 1];
    }

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

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

    fromContract(contract: IMultiFlight, { createLeg }: IFlightFactory) {
        const legs = contract.legs?.map((t) => createLeg(t)) ?? [];

        const flight: Partial<MultiLegFlight> = {
            ...contract,
            legs,
            isMultiLeg: true,
        };

        return flight;
    }
}
