syntax = "proto3";

package _common;

// Information about high-profile, military or government aircraft like
// Air Force One are not displayed. Other restricted aircraft may be anonymised,
// appearing as `BLOCKED` or `NA`.
// See [FAA's Limited Data Displayed](https://www.faa.gov/pilots/ladd) and
// [PIA program](https://www.faa.gov/air_traffic/technology/equipadsb/privacy)
// for more details.
enum RestrictionVisibility {
    NOT_VISIBLE = 0;
    PARTIALLY_VISIBLE = 1;
    FULLY_VISIBLE = 2;
}

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;
}

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;
    AIERON = 10;
}

enum Icon {
    B738 = 0; // Boeing 737-800
    FGTR = 1; // Fighter jet
    ASW20 = 2; // Glider ASW 20
    C206 = 3; // Cessna 206
    C303 = 4; // Cessna 303
    LJ60 = 5; // Learjet 60
    Q300 = 6; // Bombardier Dash 8 Q300
    B736 = 7; // Boeing 737-600
    FOKKER100 = 8; // Fokker 100
    RJ85 = 9;  // Avro RJ85
    A320 = 10; // Airbus A320
    B757 = 11; // Boeing 757
    B767 = 12; // Boeing 767
    A3ST = 13; // Airbus A300-600ST Beluga
    MD11 = 14; // McDonnell Douglas MD-11
    A330 = 15; // Airbus A330
    A343 = 16; // Airbus A340-300
    A346 = 17; // Airbus A340-600
    B777 = 18; // Boeing 777
    B747 = 19; // Boeing 747
    A380 = 20; // Airbus A380
    A225 = 21; // Antonov An-225
    SI2 = 22;  // Solar Impulse 2
    EC = 23;   // Eurocopter
    BALL = 24; // Balloon
    GRND = 25; // Ground vehicle
    SLEI = 26; // Santa Sleigh
    DRON = 27; // Drone
    SAT = 28;  // Satellite
    ISS = 29;  // International Space Station
    CONC = 30; // Concorde
}

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

// Enhanced Mode-S data (EMS)
message EMSInfo {
    int32 qnh = 1; // Altimeter setting (QFE or QNH/QNE)
    int32 amcp = 2; // MCP/FCU selected altitude (BDS4,0)
    int32 afms = 3; // FMS selected altitude (BDS4,0)
    int32 oat = 4; // Outside air temperature, [TODO: update units]
    int32 ias = 5; // Indicated airspeed (BDS6,0), knots
    int32 tas = 6; // True airspeed (BDS0,5), knots
    int32 mach = 7; // Mach number (BDS6,0), 1e3, e.g., `704` = M0.704
    int32 agps = 8; // GPS altitude
    int32 agpsdiff = 9; // Difference between amcp and agps
    int32 apflags = 10; // Autopilot flags, often null
    int32 wind_dir = 11; // Wind direction, [TODO: update units]
    int32 wind_speed = 12; // Wind speed, [TODO: update units]
    int32 rs = 13;
}

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; // Scheduled Time of Departure, Unix timestamp in seconds
    int32 etd = 2; // Estimated Time of Departure, Unix timestamp in seconds
    int32 atd = 3; // Actual Time of Departure, Unix timestamp in seconds
    int32 sta = 4; // Scheduled Time of Arrival, Unix timestamp in seconds
    int32 eta = 5; // Estimated Time of Arrival, Unix timestamp in seconds
    int32 ata = 6; // Actual Time of Arrival, Unix timestamp in seconds
    int32 progress_pct = 7; // Progress percentage of the flight
}

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

// NOTE: Attributes `operated_by_id` (15), `squawk_availability` (16),
// `vspeed_availability` (17), `airspace_availability` (18),
// `airspace_id` (19), `server_time_ms` (21)
// only available when the flight is selected.
message ExtraFlightInfo {
    string flight = 1; // IATA Flight number, e.g. `CX8747`
    string reg = 2; // Aircraft registration, e.g. `B-HUJ`
    Route route = 3;
    string type = 4; // Aircraft type code, e.g. `B744`
    int32 squawk = 5; // Squawk code, in base-10. e.g., `20852` (converted from octal)
    int32 vspeed = 6; // Vertical speed, feet per minute
    string age = 7; // Aircraft age, years in string format, e.g., `"17 years"`
    int32 country_of_reg = 8; // Country code of registration
    Schedule schedule = 9;
    int32 logo_id = 10; // Airline logo ID
    int32 airspace = 11; // FIR airspace ID
    EMSInfo ems_info = 12;
    EMSAvailability ems_availability = 13;
    uint32 icao_address = 14; // ICAO 24-bit address of the aircraft (hex)
    uint32 operated_by_id = 15; // Airline ID of the operator
    bool squawk_availability = 16;
    bool vspeed_availability = 17;
    bool airspace_availability = 18;
    string airspace_id = 19; // Airspace ID
}

message SourceStats {
    DataSource source = 1;
    uint32 count = 2; // Number of flights recorded with this source
}

message Stats {
    repeated SourceStats total_list = 1;
}

message RecentPosition {
    int32 delta_lat = 1; // Offset from the current latitude, 1e5 degrees
    int32 delta_lon = 2; // Offset from the current longitude, 1e5 degrees
    uint32 delta_ms = 3; // Delta time, milliseconds
}

message PositionBuffer {
    repeated RecentPosition recent_positions_list = 1; // List of recent positions
}

message Flight {
    int32 flightid = 1; // FR24 flight id, in base-10 integer. Convert to hex for use in URLs.
    float lat = 2; // Latitude, degrees, -90 to 90
    float lon = 3; // Longitude, degrees, -180 to 180
    int32 track = 4; // True track angle, degrees clockwise from North
    int32 alt = 5; // Barometric altitude, feet
    int32 speed = 6; // Ground speed, knots
    Icon icon = 7;
    Status status = 8;
    int32 timestamp = 9;  // Last update timestamp, Unix timestamp in seconds
    bool on_ground = 10;
    string callsign = 11; // Callsign, e.g. `CPA8747`
    DataSource source = 12;
    ExtraFlightInfo extra_info = 13;
    PositionBuffer position_buffer = 14;
    uint64 timestamp_ms = 15; // Last update timestamp, milliseconds
}

// used in FollowFlight, FlightDetails, PlaybackFlight

enum FlightStage {
    UNKNOWN = 0;
    ON_GROUND = 1;
    ASCENDING = 2;
    AIRBORNE = 3;
    DESCENDING = 4;
    DIVERSION = 5;
}

enum DelayStatus {
    GRAY = 0;
    GREEN = 1;
    YELLOW = 2;
    RED = 3;
}

message FlightProgress {
    uint32 traversed_distance = 1; // Distance traversed in the flight, meters
    uint32 remaining_distance = 2; // Remaining distance to destination, meters
    uint32 elapsed_time = 3; // Elapsed flight time, seconds
    uint32 remaining_time = 4; // Remaining flight time, seconds
    uint32 eta = 5; // Estimated Time of Arrival, Unix timestamp in seconds
    uint32 great_circle_distance = 6; // Great circle distance of the first, meters
    uint32 mean_flight_time = 7; // Mean flight time for this route, seconds
    _common.FlightStage flight_stage = 8;
    _common.DelayStatus delay_status = 9;
    uint32 progress_pct = 10; // Flight progress percentage (e.g. `82`)
}


message ImageInfo {
    string url = 1; // Image URL
    string copyright = 2; // Copyright information (e.g. `"R Skywalker"`)
    string thumbnail = 3; // URL for thumbnail image (e.g. `"https://cdn.jetphotos.com/200/5/459674_1738674373_tb.jpg"`)
    string medium = 4; // URL for medium-sized image (e.g. `"https://cdn.jetphotos.com/400/5/459674_1738674373.jpg"`)
    string large = 5; // URL for large-sized image (e.g. `"https://cdn.jetphotos.com/640/5/459674_1738674373.jpg"`)
    string sideview = 6;
}

message AircraftInfo {
    uint32 icao_address = 1; // ICAO 24-bit address of the aircraft
    string reg = 2; // Registration number
    int32 country_of_reg = 3; // Country of registration code (e.g. `3`)
    string type = 4; // Aircraft type code (e.g. `"A359"`)
    _common.Icon icon = 5;
    string full_description = 6; // Full aircraft description (e.g. `"Airbus A350-941"`)
    string msn = 7;
    _common.Service service = 8;
    string ac_birth_date = 9; // Aircraft birth date string (e.g. `"2017-06-28"`)
    uint32 ac_age = 10; // Aircraft age
    repeated ImageInfo images_list = 11;
    bool is_test_flight = 12;
    bool msn_available = 13;
    bool age_available = 14;
    string registered_owners = 15; // Aircraft owner name (e.g. `"Air France"`)
    bool is_country_of_reg_available = 16;
}

message Point {
    int32 latitude = 1; // Latitude, degrees, -90 to 90
    int32 longitude = 2; // Longitude, degrees, -180 to 180
}

message Coordinate {
    string code = 1;
    Point point = 2;
}

message Fix {
    string airport = 1;
    string area = 2;
    Coordinate coordinate = 3;
}

message AltArrival {
    Fix arrival = 1;
    float length = 2;
}

message FlightPlan {
    string departure = 1;
    string destination = 2;
    string flight_plan_icao = 3;
    double length = 4;
    AltArrival alt_arrival_1 = 5;
    AltArrival alt_arrival_2 = 6;
    repeated Point waypoints_list = 7;
}

message ScheduleInfo {
    string flight_number = 1; // Flight number with airline prefix (e.g. `"AF334"`)
    uint32 operated_by_id = 2; // ID of the operating airline (e.g. `15`)
    uint32 painted_as_id = 3; // ID of the airline the aircraft is painted as (e.g. `15`)
    uint32 origin_id = 4; // Origin airport ID (e.g. `598`)
    uint32 destination_id = 5; // Destination airport ID (e.g. `451`)
    uint32 diverted_to_id = 6; // Diverted to airport ID
    uint32 scheduled_departure = 7; // Scheduled Time of Departure, Unix timestamp in seconds
    uint32 scheduled_arrival = 8; // Scheduled Time of Arrival, Unix timestamp in seconds
    uint32 actual_departure = 9; // Actual Time of Departure, Unix timestamp in seconds
    uint32 actual_arrival = 10; // Actual Time of Arrival, Unix timestamp in seconds
    string arr_terminal = 11; // Arrival terminal (e.g. `"E"`)
    string arr_gate = 12; // Arrival gate (e.g. `"E6"`)
    string baggage_belt = 13; // Baggage belt (e.g. `"4"`)
}

message ExtendedFlightInfo {
    uint32 flightid = 1; // Flight ID (e.g. `962788562` = `0x3962fcd2`)
    float lat = 2; // Latitude, degrees, -90 to 90
    float lon = 3; // Longitude, degrees, -180 to 180
    int32 track = 4; // True track angle, degrees clockwise from North
    int32 alt = 5; // Altitude, feet
    int32 speed = 6; // Ground Speed, knots
    _common.Status status = 7;
    uint64 timestamp_ms = 8; // Unix timestamp of message, milliseconds (e.g. `1741377144019`)
    bool on_ground = 9;
    string callsign = 10; // Callsign (e.g. `"AFR334"`)
    _common.DataSource source = 11;
    _common.EMSAvailability ems_availability = 12;
    _common.EMSInfo ems_info = 13;
    bool squawk_availability = 14;
    int32 squawk = 15; // Squawk code, in base-10 (e.g. `3041` = 0o5741)
    bool vspeed_availability = 16;
    int32 vspeed = 17; // Vertical speed (e.g. `3328`)
    bool airspace_availability = 18;
    string airspace = 19; // Airspace, free-form text (e.g. `"Shannon UIR"`)
    string airspace_id = 20; // Airspace ID (e.g. `"FIR_EINN_U"`)
    uint64 server_time_ms = 21; // Server timestamp, Unix timestamp in milliseconds (e.g. `1741377145974`)
}

message TrailPoint {
    uint64 snapshot_id = 1; // Snapshot ID, likely Unix timestamp in seconds (e.g. `1741356300`)
    float lat = 2; // Latitude, degrees, -90 to 90
    float lon = 3;  // Longitude, degrees, -180 to 180
    int32 altitude = 4; // Altitude, feet
    uint32 spd = 5; // Ground speed, knots
    // True track angle, degrees clockwise from North.
    // Note: despite the name, heading is not transmitted in ADS-B.
    uint32 heading = 6;
    int32 vspd = 7; // Vertical Speed, feet per minute
    _common.DataSource source = 8;
}

// NOTE: unused anywhere
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;
}

// used in CountDown service
message Duration {
    uint32 count = 1;
}

message Tick {
    uint32 count = 1;
}

// used in *trail services
message RadarHistoryRecord {
    uint64 timestamp = 1; // Observation timestamp, Unix timestamp in seconds
    float lat = 2;        // Latitude, degrees, -90 to 90
    float lon = 3;        // Longitude, degrees, -180 to 180
    int32 altitude = 4;   // Altitude, feet
    uint32 spd = 5;       // Ground Speed, knots
    // True track angle, degrees clockwise from North.
    // Note: despite the name, heading is not transmitted in ADS-B.
    uint32 heading = 6;
    int32 vspd = 7;       // Vertical speed, feet per minute
    uint32 squawk = 8;
    _common.DataSource source = 9;
    string callsign = 10; // Callsign, e.g. `CPA959`
}
