syntax = "proto3";

package juturna.proto.payloads;

import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";

// AudioProtoPayload represents audio data with metadata
// Uses raw bytes for maximum efficiency instead of repeated floats
message AudioProtoPayload {
  // Raw audio samples as bytes (use numpy.tobytes() for serialization)
  bytes audio_data = 1;

  // Data type of audio samples (e.g., "float32", "int16", "float64")
  string dtype = 2;

  // Shape of the audio array [samples, channels]
  // For mono: [samples], for stereo: [samples, 2]
  repeated int32 shape = 3;

  // Sampling rate in Hz (e.g., 44100, 48000)
  int32 sampling_rate = 4;

  // Number of audio channels (1 for mono, 2 for stereo, etc.)
  int32 channels = 5;

  // Start timestamp in seconds
  double start = 6;

  // End timestamp in seconds
  double end = 7;

  // Audio format
  string audio_format = 8;
}

// ImageProtoPayload represents a single frame/image
// Uses raw bytes for maximum compression efficiency
message ImageProtoPayload {
  // Raw pixel data as bytes (flattened array)
  // Reshape using: image_data.reshape(height, width, depth)
  bytes image_data = 1;

  // Data type of pixels (e.g., "uint8", "float32", "uint16")
  string dtype = 2;

  // Image width in pixels
  int32 width = 3;

  // Image height in pixels
  int32 height = 4;

  // Color depth (e.g., 1 for grayscale, 3 for RGB, 4 for RGBA)
  int32 depth = 5;

  // Pixel format (e.g., "RGB", "RGBA", "BGR", "GRAY", "HSV")
  string pixel_format = 6;

  // Frame timestamp in seconds
  double timestamp = 7;
}

// VideoProtoPayload represents a sequence of frames
message VideoProtoPayload {
  // Sequence of image frames
  repeated ImageProtoPayload frames = 1;

  // Frame rate in frames per second (fps)
  double frames_per_second = 2;

  // Video start timestamp in seconds
  double start = 3;

  // Video end timestamp in seconds
  double end = 4;

  // Optional: video codec information
  string codec = 5;
}

// BytesProtoPayload for generic binary content
message BytesProtoPayload {
  // Raw binary content
  bytes cnt = 1;

  // Optional: size in bytes (can be computed from content.length)
  int64 size = 2;
}

// BatchProto represents a collection of messages
message BatchProto {
  // List of messages in the batch
  repeated ProtoMessage messages = 1;
}

// ObjectProtoPayload for arbitrary key-value structures
// Equivalent to Python dict or JSON object
message ObjectProtoPayload {
  // Arbitrary structured data using protobuf Struct
  // Supports nested objects, arrays, strings, numbers, booleans, null
  google.protobuf.Struct data = 1;
}

// ProtoMessage represents a single message in the system
// This is the core message type that flows through nodes
message ProtoMessage {
  // ProtoMessage creation timestamp (Unix epoch in seconds)
  double created_at = 1;

  // Creator node name (identifies which node created this message)
  string creator = 2;

  // ProtoMessage version (indicates version of the data contained)
  int32 version = 3;

  // ProtoPayload can be any of the payload types (AudioProtoPayload, ImageProtoPayload, etc.)
  google.protobuf.Any payload = 4;

  // Metadata (flexible metadata storage)
  google.protobuf.Struct meta = 5;

  // Timers for performance tracking
  // Key: timer name, Value: elapsed time in seconds
  map<string, double> timers = 6;

  // ProtoMessage id (indicates the id of the data contained)
  int32 id = 10;

}

// ProtoEnvelope is the top-level message sent over the wire
// It wraps a ProtoMessage and adds routing, correlation, and lifecycle information
message ProtoEnvelope {
  // Unique envelope identifier (UUID recommended)
  string id = 1;

  // The actual message being transported
  ProtoMessage message = 2;

  // Sender identifier
  string sender = 3;

  // Intended receiver identifier
  string receiver = 4;

  // Response-to field: ID of the envelope this is responding to
  // Enables explicit request/response tracking
  string response_to = 6;

  // Time-to-live in seconds
  // After this duration, the message may be considered stale/expired
  int64 ttl = 7;

  // Envelope creation timestamp (Unix epoch in seconds)
  double created_at = 8;

  // Configuration parameters as key-value pairs
  // these message are used to the set_on_config call
  google.protobuf.Struct configuration = 9;

  // Envelope metadata as key-value pairs
  // Different from message.meta - this is envelope-level metadata
  google.protobuf.Struct metadata = 10;

  // message priority (0 = lowest, higher = more urgent)
  // for future use
  int32 priority = 11;

  // request payload (not proto) type hint for faster routing/dispatching
  // e.g., "AudioPayload"
  string request_type = 12;

  // response payload (not proto) type hint for faster serialization
  // e.g., "ImagePayload"
  string response_type = 13;

}

// Optional: Compressed payload wrapper for large data
message CompressedProtoPayload {
  // Compression algorithm used (e.g., "gzip", "zstd", "lz4")
  string compression = 1;

  // Compressed data
  bytes compressed_data = 2;

  // Original uncompressed size in bytes
  int64 original_size = 3;

  // Compressed size in bytes (can be computed from compressed_data.length)
  int64 compressed_size = 4;

  // Original payload type before compression
  string original_type = 5;
}
