syntax = "proto3";

package cmvr.quic_gateway.v1;

option java_package = "com.cmvr.quic.gateway.v1";
option java_multiple_files = true;
option java_outer_classname = "QuicGatewayProtocol";

enum NodeEventType {
  NODE_EVENT_TYPE_UNSPECIFIED = 0;
  NODE_EVENT_TYPE_REGISTERED = 1;
  NODE_EVENT_TYPE_HEARTBEAT = 2;
  NODE_EVENT_TYPE_OFFLINE = 3;
  NODE_EVENT_TYPE_MEDIA_CHANGED = 4;
}

message NodeEvent {
  NodeEventType type = 1;
  NodeSnapshot node = 2;
  uint64 event_time_unix_ms = 3;
}

message NodeSnapshot {
  string node_id = 1;
  string boot_id = 2;
  string session_id = 3;
  string software_version = 4;
  bool online = 5;
  uint64 registered_at_unix_ms = 6;
  uint64 last_heartbeat_at_unix_ms = 7;
  uint64 heartbeat_sequence = 8;
  string observed_source_ip = 9;
  GrpcEndpoint grpc_endpoint = 10;
  repeated NetworkInterfaceAddress local_interfaces = 11;
  DeviceManagerSnapshot device_manager = 12;
  uint64 media_session_epoch = 13;
  repeated MediaTrack tracks = 14;
}

message GrpcEndpoint {
  string host = 1;
  uint32 port = 2;
  bool tls = 3;
}

message NetworkInterfaceAddress {
  string interface_name = 1;
  string ip_address = 2;
  int32 family = 3;
  bool loopback = 4;
}

message DeviceManagerSnapshot {
  string manager_name = 1;
  string manager_version = 2;
  string manager_description = 3;
  uint64 sampled_at_unix_ms = 4;
  repeated ManagedDeviceStatus devices = 5;
}

message ManagedDeviceStatus {
  string device_id = 1;
  int32 kind = 2;
  string type_name = 3;
  bool enabled = 4;
  int32 manager_state = 5;
  int32 health = 6;
  bool has_error = 7;
  string error_message = 8;
  uint64 status_updated_at_unix_ms = 9;
}

message MediaTrack {
  uint32 track_id = 1;
  int32 kind = 2;
  string device_id = 3;
  string source_track_id = 4;
  string codec = 5;
  string payload_format = 6;
  uint64 codec_generation = 7;
  uint32 codec_generation_token = 8;
  uint32 width = 9;
  uint32 height = 10;
  uint32 frames_per_second = 11;
  uint32 sample_rate = 12;
  uint32 channels = 13;
  bytes codec_config = 14;
}

message MediaFrame {
  string node_id = 1;
  string session_id = 2;
  uint64 session_epoch = 3;
  uint32 track_id = 4;
  int32 kind = 5;
  string codec = 6;
  string payload_format = 7;
  uint64 packet_sequence = 8;
  uint64 frame_sequence = 9;
  uint64 capture_timestamp_us = 10;
  uint32 flags = 11;
  bytes payload = 12;
}
