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

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

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