import { RouteType } from '@typings/enums';
import { IWithLeg } from './types';

export function getFlightLastLeg(flight: IWithLeg) {
    switch (flight.routeType) {
        case RouteType.CONNECTING: {
            return getFlightLastLeg(flight.flights[flight.flights.length - 1]);
        }
        case RouteType.DIRECT: {
            return flight.leg;
        }
        case RouteType.MULTI_LEG: {
            return flight.legs[flight.legs.length - 1];
        }
    }
}
