declare global {
    const route: typeof import('ziggy-js')['route']
}

declare module '@vue/runtime-core' {
    interface ComponentCustomProperties {
        route: typeof import('ziggy-js')['route']
    }
}

export type ProfileView = 'map' | 'board' | 'passes' | 'achievements' ;
export type ChartType = "line" | "area" | "bar" | "pie" | "donut" | "radialBar" | "scatter" | "bubble" | "heatmap" | "candlestick" | "boxPlot" | "radar" | "polarArea" | "rangeBar" | "rangeArea" | "treemap" | undefined
export type BadgeVariant = 'first' | 'business' | 'premium' | 'economy' | 'private' | 'unspecified' | 'generic' | 'general_aviation' | 'crew' | "easy" | "moderate" | "hard" | "expensive" | "near_impossible" | "impossible"

export interface User {
    id: number
    name: string
    email: string
    email_verified_at: string | null
    resolved_settings?: UserSettings
}

export type DistanceUnit = "km" | "mi" | "nm"

export interface UserSettings {
    distance_unit: DistanceUnit
    show_ai_tail_logos: boolean
    show_ai_livery_images: boolean
    departure_board_columns: string[]
    show_map_legend: boolean
    hide_impossible_achievements: boolean
    hide_map_filters: boolean
}


export interface FollowerEntry {
    user: User
    verified: boolean
}

export type SettingType = 'select' | 'text' | 'checkbox' | 'multiselect'
export interface SettingOption {
    value: string
    label: string
}

export interface SettingField {
    key: keyof UserSettings
    type: SettingType
    label: string
    category: string
    default: UserSettings[keyof UserSettings]
    value: UserSettings[keyof UserSettings]
    options?: SettingOption[]
}

export type UserActionType = "flight_cancelled" | "flight_booked" | "flight_updated" | "flight_logged" | "flight_deleted" | "flight_imported" | "flight_departing" | "flight_arriving"
export type UserActionDataKey = "field" | "from" | "to"

export type UserActionFlightBookedData = {
    flight: Flight
}

export type UserActionFlightCancelledData = {
    flight: Flight
}

export type UserActionFlightUpdatedData = {
    changes: UserActionChange[],
    original: Flight,
    updated: Flight
}

export type UserActionChange = {field: string, from: string, to: string}
export type UserActionData = UserActionFlightBookedData | UserActionFlightCancelledData | UserActionFlightUpdatedData

export interface Alliance {
    id: number
    name: string
    internal_name: string
}

export interface UserAction {
    id: number
    user_id: number
    type: UserActionType
    data: UserActionData
    created_at: string
    updated_at: string
    user: User
    display_type: string
    user_flight: Flight
}

export type SharedProps = import('@inertiajs/core').PageProps & {
    auth: {
        user: User | null
        isLoggedIn: boolean
        roles: string[];
        permissions: string[];
        apiToken: string | null;
    },
    flash: {
        success?: string;
        error?: string;
    },
    logo_api_url: string
    achievement_notifications: Notification[]
    unread_notification_count: number
}
export interface AchievementDifficulty {
    id: number
    internal_name: "easy" | "moderate" | "hard" | "expensive" | "near_impossible" | "impossible"
    name: string
    description: string
    created_at: string | null
    updated_at: string | null
}

export interface AchievementCategory {
    id: number
    internal_name: string
    name: string
    description: string
    created_at: string | null
    updated_at: string | null
}

export interface Achievement {
    id: number
    name: string
    internal_name: string
    icon: string
    short_description: string
    long_description: string
    progressive: boolean
    difficulty_description: string | null
    threshold: number | null
    achievement_category_id: number
    achievement_difficulty_id: number
    category?: AchievementCategory
    difficulty: AchievementDifficulty
    has_page: boolean
    sort_order: number
}

export interface UserAchievement {
    id: number
    user_id: number
    achievement_id: number
    unlocked: boolean
    progress: number | null
    achievement?: Achievement
    created_at: string | null
    updated_at: string | null
}

export interface Notification {
    id: number
    user_id: number
    title: string
    body: string
    url: string | null
    is_achievement: boolean
    achievement_id: number | null
    achievement?: Achievement | null
    read_at: string | null
    expires_at: string | null
    created_at: string | null
    updated_at: string | null
}

export interface Region {
    id: number
    name: string
    code: string
    local_code: string
    country_id: number
    continent_id: number
    created_at: string | null
    updated_at: string | null
    continent: Continent
    country: Country
}

export interface Airport {
    id: number
    name: string
    latitude_deg: number
    longitude_deg: number
    elevation_ft: number | null
    region_id: number
    region?: Region
    municipality: string | null
    icao_code: string | null
    iata_code: string | null
    local_code: string | null
    type: string
    created_at: string | null
    updated_at: string | null
    timezone: string
    display_code: string
    display_name: string
}

export type Continent = {
    id: number
    name: string
    code: string
    internal_name:string
}

export type Country = {
    id: number
    code: string
    name: string
    created_at: string | null
    updated_at: string | null
    continent_id: number
    continent?: Continent
}

export interface Airline {
    id: number
    iata_code: string | null
    icao_code: string | null
    name: string
    internal_name: string
    active: boolean
    logo: string | null
    country_id: number
    country?: Country
    display_name: string
    logo_url: string
    alliance_id: number | null,
    alliance?: Alliance,
    merged_from?: Airline[] ,
}

export interface Aircraft {
    id: number
    designator: string
    manufacturer_code: string
    model_full_name: string
    aircraft_description: string
    engine_type: string
    engine_count: number
    wtc: string
    created_at: string | null
    updated_at: string | null
    display_name: string
    display_name_short: string
}

export interface SeatType {
    id: number
    name: string
}

export interface FlightReason {
    id: number
    name: string
}

export interface FlightClass {
    id: number
    name: string
    internal_name: BadgeVariant
}

export interface CrewType {
    id: number
    name: string
    internal_name: string
}

export type RegionRange = "intraregional" | "interregional"
export type FlightScope = 'domestic' | 'international'
export type FlightRange = 'intracontinental' | 'intercontinental'

export interface Livery{
    image_url: string,
    is_ai: boolean,
    attribution: string,
    attribution_url: string,
}

export interface Flight {
    id: number
    flight_number: string | null
    departure_date: string
    arrival_date: string
    aircraft_registration: string | null
    seat_number: string | null
    note: string | null
    departure_airport: Airport
    arrival_airport: Airport
    departure_date_display: string,
    arrival_date_display: string,
    departure_time_display: string,
    arrival_time_display: string,
    arrival_day_difference: number,
    airline: Airline | null
    aircraft: Aircraft | null
    seat_type: SeatType | null
    crew_type?: CrewType | null
    flight_reason: FlightReason | null
    flight_class: FlightClass | null
    duration_display: string
    duration: number
    distance: number
    scope: FlightScope
    range: FlightRange
    region_range: RegionRange
    livery: Livery | null
    user?: User | null
    class_seat_combined: number
    other_users_on_flight: string[]
}


export interface MissingLivery {
    airline_name: string;
    aircraft_display_name: string;
    filename: string;
    clipboard_text: string;
}

export interface MissingAirline{
    code: string;
    flights: {
        flight_number: string;
        link: string;
    }[]
}

declare module '@inertiajs/vue3' {
    interface PageProps extends SharedProps {}
}
