import { Pipe, PipeTransform } from '@angular/core';
import { IStation } from '../models-legacy';

@Pipe({
    name: 'airportTerminal',
})
export class AirportTerminalPipe implements PipeTransform {
    transform(
        model: IStation,
        separator: 'dash' | 'brackets' = 'dash',
        onlyTerminal = false,
        oldValue = false,
    ): string {
        if (!model?.latest && !model?.scheduled) {
            return '';
        }

        const targetAirport = oldValue
            ? model.scheduled
            : model.latest ?? model.scheduled;

        if (!model.terminal) {
            return `${targetAirport.airport}`;
        }

        if (onlyTerminal) {
            return `${model.terminal}`;
        }

        return separator === 'dash'
            ? `${targetAirport.airport} - ${model.terminal}`
            : `${targetAirport.airport} (${model.terminal})`;
    }
}
