import { FlightModel } from './models-legacy';

export interface AirlinesReference<T> {
    Aeroflot: T;
    Aurora: T;
    Rossiya: T;
    Pobeda: T;
    AirFrance: T;
}

export const AirlineCodes: AirlinesReference<string> = {
    Aeroflot: 'SU',
    Aurora: 'HZ',
    Rossiya: 'FV',
    Pobeda: 'DP',
    AirFrance: 'AF',
};

export const airlineCodes = Object.values(AirlineCodes);

export interface Airline {
    code: string;
    url: string;
    registrationUrl: string;
    canViewStatus: boolean;
    canViewNativeStatus: boolean;
    canRedirect: boolean;
    canRegister: boolean;
}

export const Airlines: AirlinesReference<Airline> = {
    Aeroflot: {
        code: AirlineCodes.Aeroflot,
        url: 'https://www.aeroflot.ru/sb/ckin/app/ru-ru',
        registrationUrl: 'https://www.aeroflot.ru/sb/ckin/app/ru-ru',
        canViewStatus: true,
        canViewNativeStatus: true,
        canRedirect: false,
        canRegister: true,
    },
    Aurora: {
        code: AirlineCodes.Aurora,
        url: 'https://www.flyaurora.ru',
        registrationUrl: 'https://www.flyaurora.ru',
        canViewStatus: true,
        canViewNativeStatus: false,
        canRedirect: true,
        canRegister: true,
    },
    Rossiya: {
        code: AirlineCodes.Rossiya,
        url: 'https://www.rossiya-airlines.com',
        registrationUrl: 'https://www.rossiya-airlines.com/flight-with-us/before_flight/the_ways_of_check-in/',
        canViewStatus: true,
        canViewNativeStatus: true,
        canRedirect: false,
        canRegister: true,
    },
    Pobeda: {
        code: AirlineCodes.Pobeda,
        url: 'https://www.pobeda.aero',
        registrationUrl: 'https://www.pobeda.aero',
        canViewStatus: true,
        canViewNativeStatus: false,
        canRedirect: true,
        canRegister: true,
    },
    AirFrance: {
        code: AirlineCodes.AirFrance,
        url: '',
        registrationUrl: '',
        canViewStatus: false,
        canViewNativeStatus: false,
        canRedirect: false,
        canRegister: false,
    },
};

export const airlines: Airline[] = Object.values(Airlines);

export function getAirline(flight?: FlightModel): Airline | undefined {
    if (!flight) return;
    const { operatingBy } = flight;
    const code = operatingBy?.actual || operatingBy?.scheduled;
    return airlines.find((a) => a.code === code);
}
