import { RouteType } from '@typings/enums';
import { IWithLeg } from '@utils/flight/legs/types';
import { getStationCity } from '@utils/flight/station';

export function getFlightArrivalCity(flight: IWithLeg) {
    switch (flight.routeType) {
        case RouteType.CONNECTING: {
            return getFlightArrivalCity(
                flight.flights[flight.flights.length - 1],
            );
        }
        case RouteType.MULTI_LEG: {
            const { arrival } = flight.legs[flight.legs.length - 1];

            return getStationCity(arrival);
        }
        case RouteType.DIRECT: {
            return getStationCity(flight.leg.arrival);
        }
    }
}
