syntax = "proto3";
// NOTE: the optional keyword doesn't mean it's nullable, but for presence tracking which forces the field to be explicitly sent
// we try to adhere to the official structure and naming as far as possible.
// when ambiguous, mark as ? or unofficial

enum RestrictionVisibility {
    NOT_VISIBLE = 0;
    PARTIALLY_VISIBLE = 1; // changed: 24.169.0808
    FULLY_VISIBLE = 2; // changed: 24.169.0808
}

enum Service {
    PASSENGER = 0;
    CARGO = 1;
    MILITARY_AND_GOVERNMENT = 2;
    BUSINESS_JETS = 3;
    GENERAL_AVIATION = 4;
    HELICOPTERS = 5;
    LIGHTER_THAN_AIR = 6;
    GLIDERS = 7;
    DRONES = 8;
    GROUND_VEHICLES = 9;
    OTHER_SERVICE = 10;
    NON_CATEGORIZED = 11;
}

message AirportFilter {
    string iata = 1;
    int32 country_id = 2;
    AirportFilterType type = 3;
}
    
enum AirportFilterType {
    BOTH = 0;
    INBOUND = 1;
    OUTBOUND = 2;
}

message AirlineFilter {
    string icao = 1; // e.g. CPA
    AirlineFilterType type = 2;
}

enum AirlineFilterType {
    PAINTED_AS = 0;
    OPERATED_AS = 1;
}

message Filter {
    message AltitudeRange { // ?
        int32 min = 1;
        int32 max = 2;
    } // feet

    message SpeedRange { // ?
        int32 min = 1;
        int32 max = 2;
    } // knots

    message BirthYearRange { // ?
        int32 min = 1;
        int32 max = 2;
    }

    message ODFilter { // ?
        string iata = 1;
        int32 country_id = 2;
    }

    repeated AltitudeRange altitude_ranges_list = 1;
    repeated SpeedRange speed_ranges_list = 2; // NOTE: ground speed
    repeated AirlineFilter airlines_list = 3;
    repeated string callsigns_list = 4;
    repeated string radars_list = 5; // receiver: e.g. T-VHST000
    repeated string regs_list = 6;
    repeated AirportFilter airports_list = 7;
    // repeated Flight? flights_list = 8;
    repeated string types_list = 9; // e.g. B7*
    repeated BirthYearRange birth_year_ranges_list = 10;
    // repeated Squawk? squawks_list = 11;
    repeated ODFilter origins_list = 12;
    repeated ODFilter destinations_list = 13;
    repeated Service categories_list = 14;
    // repeated ? ? = 15;
}

enum TrafficType {
    NONE = 0;
    GROUND_ONLY = 1;
    AIRBORNE_ONLY = 2;
    ALL = 3;
}

enum DataSource {
    ADSB = 0;
    MLAT = 1;
    FLARM = 2;
    FAA = 3;
    ESTIMATED = 4;
    SATELLITE = 5;
    OTHER_DATA_SOURCE = 6;
    UAT = 7;
    SPIDERTRACKS = 8;
    AUS = 9;
}

enum Icon {
    B738 = 0;
    FGTR = 1;
    ASW20 = 2;
    C206 = 3;
    C303 = 4;
    LJ60 = 5;
    Q300 = 6;
    B736 = 7;
    FOKKER100 = 8;
    RJ85 = 9;
    A320 = 10;
    B757 = 11;
    B767 = 12;
    A3ST = 13;
    MD11 = 14;
    A330 = 15;
    A343 = 16;
    A346 = 17;
    B777 = 18;
    B747 = 19;
    A380 = 20;
    A225 = 21;
    SI2 = 22;
    EC = 23;
    BALL = 24;
    GRND = 25;
    SLEI = 26;
    DRON = 27;
    SAT = 28;
    ISS = 29;
}

enum Status {
    NORMAL = 0;
    BACKGROUND = 1;
    EMERGENCY = 2;
    NOT_AVAILABLE = 3;
    LIVE = 4;
}

message VisibilitySettings {
    repeated DataSource sources_list = 1;
    repeated Service services_list = 2;
    TrafficType traffic_type = 3;
    optional bool only_restricted = 4;
}

message LocationBoundaries {
    float north = 1;
    float south = 2;
    float west = 3;
    float east = 4;
}

message LiveFeedRequest {
    message FieldMask { // ? 
        repeated string field_name = 1;
    }

    LocationBoundaries bounds = 1;
    VisibilitySettings settings = 2;
    Filter filters_list = 3;
    string fleets_list = 4; // requires auth
    bool highlight_mode = 5;
    optional bool stats = 6;
    optional int32 limit = 7; // default 1500/2000
    optional int32 maxage = 8; // default 14400
    optional RestrictionVisibility restriction_mode = 9;
    FieldMask field_mask = 10;
    repeated fixed32 selected_flight_ids_list = 11;
}

// a =? altitude
message EMSInfo {
    int32 qnh = 1; // often null
    int32 amcp = 2; // likely barometric altitude
    int32 afms = 3; // often null
    int32 oat = 4;
    int32 ias = 5;
    int32 tas = 6;
    int32 mach = 7; // NOTE: 1000 = mach 1
    int32 agps = 8;
    int32 agpsdiff = 9; // |amcp - agps|
    int32 apflags = 10; // often null
    int32 wind_dir = 11;
    int32 wind_speed = 12;
    int32 rs = 13; // unknown
}

message EMSAvailability {
    bool qnh_availability = 1;
    bool amcp_availability = 2;
    bool afms_availability = 3;
    bool oat_availability = 4;
    bool ias_availability = 5;
    bool tas_availability = 6;
    bool mach_availability = 7;
    bool agps_availability = 8;
    bool agpsdiff_availability = 9;
    bool apflags_availability = 10;
    bool wind_dir_availability = 11;
    bool wind_speed_availability = 12;
    bool rs_availability = 13;
}

message Schedule {
    int32 std = 1;
    int32 etd = 2;
    int32 atd = 3;
    int32 sta = 4;
    int32 eta = 5; //!
    int32 ata = 6;
}

message ExtraFlightInfo {
    message Route {
        string from_ = 1;
        string to = 2;
    }

    string flight = 1; // iata flight number
    string reg = 2;
    Route route = 3;
    string type = 4;
    int32 squawk = 5; // NOTE: 20852 -> 0x5174
    int32 vspeed = 6;
    string age = 7; // aircraft age, in years
    int32 country_of_reg = 8;
    Schedule schedule = 9;
    int32 logo_id = 10; // u32
    int32 airspace = 11; // FIR
    EMSInfo ems_info = 12;
    EMSAvailability ems_availability = 13;
    int32 icao_address = 14;
    // following are untested, activated only when flight is selected
    // int32? operated_by_id = 15;
    // int32? squawk_availability = 16;
    // bool vspeed_availability = 17;
    // bool airspace_availability = 18;
    // ? airspace_id = 19;
}

message SourceStats {
    DataSource source = 1;
    int32 count = 2;
}

message Stats {
    repeated SourceStats sources = 1;
}

message Flight {
    int32 flightid = 1; // to hex
    float lat = 2;
    float lon = 3;
    int32 track = 4;
    int32 alt = 5;
    int32 speed = 6; // ground speed
    Icon icon = 7;
    Status status = 8;
    int32 timestamp = 9;
    bool on_ground = 10;
    string callsign = 11;
    DataSource source = 12;
    ExtraFlightInfo extra_info = 13;
}

message LiveFeedResponse {
    repeated Flight flights_list = 1;
    Stats stats = 2;
    repeated Flight selected_flight_info = 3;
}

// duration: floor(7.5*(multiplier)) seconds, i.e. 1x = 7s
message PlaybackRequest {
    LiveFeedRequest live_feed_request = 1;
    int32 timestamp = 2; // 1x: 7 second intervals
    int32 prefetch = 3;
    optional int32 hfreq = 4;
}

message PlaybackResponse {
    LiveFeedResponse live_feed_response = 1;
}


// ununsed

message AircraftInfo {
    int32 icao_address = 1;
    int32 reg = 2;
    int32 country_of_reg = 3;
    string type = 4;
    Icon icon = 5;
    string full_description = 6;
    string msn = 7;
    Service service = 8;
    string ac_birth_date = 9;
    string ac_age_text = 10;
    repeated ImageInfo images_list = 11;
    bool is_test_flight = 12;
    bool msn_available = 13;
    bool age_available = 14;
    string registered_owners = 15;
} // new: 24.169.0808

message AltArrival {
    Fix arrival = 1;
    float length = 2;
} // new: 24.169.0808

message Coordinate {
    string code = 1;
    Point point = 2;
} // new: 24.169.0808

message Duration {
    uint32 count = 1;
} // new: 24.169.0808

enum EmergencyStatus {
    NO_EMERGENCY = 0;
    GENERAL_EMERGENCY = 1;
    LIFEGUARD_MEDICAL_EMERGENCY = 2;
    MINIMUM_FUEL = 3;
    NO_COMMUNICATIONS = 4;
    UNLAWFUL_INTERFERENCE = 5;
    DOWNED_AIRCRAFT = 6;
    RESERVED = 7;
}

message ExtendedFlightInfo {
    // ? flightid = 1;
    // ? lat = 2;
    // ? lon = ?;
    // ? track = ?;
    // ? alt = ?;
    // ? speed = ?;
    // ? icon = ?;
    // ? status = 7;
    uint64 timestamp = 8;
    bool on_ground = 9;
    string callsign = 10;
    // ? source = 11;
    // ? ems_availability = 12;
    // ? ems_info = 13;
    // ? squawk_availability = 14;
    // ? squawk = 15;
    bool vspeed_availability = 16;
    int32 vspeed = 17;
    // ? airspace_availability = 18;
    // ? airspace = 19;
} // new: 24.169.0808

enum FlightStage {
    UNKNOWN = 0;
    ON_GROUND = 1;
    TAKING_OFF = 2;
    AIRBORNE = 3;
    ON_APPROACH = 4;
} // new: 24.169.0808
    
message FetchSearchIndexRequest {} // new: 24.169.0808

message FetchSearchIndexResponse {
    // repeated ? flights_list = 1;
} // new: 24.169.0808

message Fix {
    // ? airport = 1;
    // ? area = 2;
    Coordinate coordinate = 3;
} // new: 24.169.0808

message FlightPlan {
    // ? departure = 1;
    // ? destination = 2;
    // ? flight_plan_icao = 3;
    // ? length = 4;
    // ? alt_arrival_1 = 5;
    // ? alt_arrival_2 = 6;
    // repeated ? waypoints_list = 7;
} // new: 24.169.0808

message FlightProgress {} // new: 24.169.0808

message FlightSearchData {
    // ? reg = 1;
    // ? schd_from = 2;
    // ? schd_to = 3;
    // ? flight = 4;
    // ? operator = 5;
    // ? ac_type = 6;
    // ? lat = 7;
    // ? lon = 8;
    // ? callsign = 9;
    // ? id = 10;
    // ? restricted = 11;
}

message FollowFlightRequest {}

message FollowFlightResponse {
    AircraftInfo aircraft_info = 1;
    FlightPlan flight_plan = 2;
    ScheduleInfo schedule_info = 3;
    FlightProgress flight_progress = 4;
    ExtendedFlightInfo flight_info = 5;
    repeated TrailPoint flight_trail_list = 6;
}

message FollowedFlight {
    // number? flight_id = 1;
    // number? live_clicks = 2;
    // number? total_clicks = 3;
    string flight_number = 4;
    string callsign = 5;
    // number? squawk = 6;
    string from_iata = 7;
    string from_city = 8;
    string to_iata = 9;
    string to_city = 10;
    string type = 11;
    string full_description = 12;
} // new: 24.169.0808

message Geolocation {
    float lat = 1;
    float lon = 2;
}

message ImageInfo {
    string url = 1;
    string copyright = 2;
    string thumbnail = 3;
    string medium = 4;
    string large = 5;
} // new: 24.169.0808

message Interval {
    int32 min = 1;
    int32 max = 2;
}

message LiveFlightStatusData {
    float lat = 1;
    float lon = 2;
    // ? status = 3;
    uint32 squawk = 4;
}

message LiveFlightsStatusRequest {
    // repeated fixed32? flight_ids_list = 1;
}

message LiveFlightsStatusResponse {
    LiveFlightStatusData flights_map = 1; // ?
}

message LiveTrailRequest {
    // number? flight_id = 1;
} // new: 24.169.0808

message LiveTrailResponse {
    repeated RadarHistoryRecord radar_records_list = 1; // ?
} // new: 24.169.0808

message NearbyFlight {
    Flight flight = 1;
    uint32 distance = 2;
}

message NearestFlightsRequest {
    // ? location = 1;
    uint32 radius = 2;
    // ? limit = 1
}

message NearestFlightsResponse {
    repeated NearbyFlight flights_list = 1; // ?
}

message Point {
    // number? latitute = 1;
    // number? longitude = 2;
} // new: 24.169.0808

message Ping {
    // ? a = 1;
    // ? b = 2;
}

message Pong {
    // ? ? = 1;
}

message RadarHistoryRecord {
    uint64 timestamp = 1;
    // float? lat = 2;
    // float? lon = 3;
    // int32? altitude = 4;
    // int32? spd = 5;
    // int32? heading = 6; // official naming says heading, but data is likely track
    // int32? vspd = 7;
    // int32? squawk = 8;
    // DataSource? source = 9;
    // string? callsign = 10;
} // new: 24.169.0808

message Route {
    // ? from = 1;
    // ? to = 2;
    // ? diverted_to = 3;
}

message ScheduleInfo {
    string flight_number = 1;
    uint32 operated_by_id = 2;
    // uint32? painted_as_id = 3;
    // uint32? origin_id = 4;
    // uint32? destination_id = 5;
    // uint32? diverted_to_id = 6;
    uint32 scheduled_departure = 7;
    uint32 scheduled_arrival = 8;
    // uint32? actual_departure = 9;
    uint32 actual_arrival = 10;
    string arr_terminal = 11;
    string arr_gate = 12;
    string baggage_belt = 13;
} // new: 24.169.0808

message Tick {
    // ? count = 1;
} // new: 24.169.0808

message TopFlightsRequest {
    uint32 limit = 1;
} // new: 24.169.0808

message TopFlightsResponse {
    // ? scoreboard_list = 2;
} // new: 24.169.0808

message TrailPoint {
    // ? snapshot_id = 1;
    // ? lat = 2;
    // ? lon = 3;
    // ? altitude = 4;
    // ? spd = 5;
    // ? heading = 6;  // official naming says heading, but data is likely track
    // ? vspd = 7;
} // new: 24.169.0808
