// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package dataplane.proto.v1;

service DataPlaneService {
  rpc OpenChannel(stream Message) returns (stream Message) {}
}

message Subscribe {
  SLIMHeader header = 1;
  string component_0 = 2;
  string component_1 = 3;
  string component_2 = 4;
}

message Unsubscribe {
  SLIMHeader header = 1;
  string component_0 = 2;
  string component_1 = 3;
  string component_2 = 4;
}

message Publish {
  SLIMHeader header = 1;
  SessionHeader session = 2;
  Content msg = 3;
}

// recvFrom = connection from where the sub/unsub is supposed to be received
// forwardTo = connection where to forward the message
// incomingConn = connection from where the packet was received
// error = if true the publication contains an error notification
message SLIMHeader {
  Name source = 1;
  Name destination = 2;
  uint32 fanout = 3;
  optional uint64 recvFrom = 4;
  optional uint64 forwardTo = 5;
  optional uint64 incomingConn = 6;
  optional bool error = 7;
}

message Name {
  uint64 component_0 = 1;
  uint64 component_1 = 2;
  uint64 component_2 = 3;
  uint64 component_3 = 4;
}

// Used in publication messages to carry the original string name.
// Used in session layer and it is optional.
message OriginalName {
  string component_0 = 1;
  string component_1 = 2;
  string component_2 = 3;
  uint64 component_3 = 4;
}

enum SessionType {
  SESSION_UNKNOWN = 0;
  SESSION_POINT_TO_POINT = 1;
  SESSION_MULTICAST = 2;
}

enum SessionMessageType {
  UNSPECIFIED = 0;
  P_2_P_MSG = 1;
  P_2_P_RELIABLE = 2;
  P_2_P_ACK = 3;
  MULTICAST_MSG = 4;
  RTX_REQUEST = 5;
  RTX_REPLY = 6;
  BEACON_MULTICAST = 7;
  CHANNEL_DISCOVERY_REQUEST = 8;
  CHANNEL_DISCOVERY_REPLY = 9;
  CHANNEL_JOIN_REQUEST = 10;
  CHANNEL_JOIN_REPLY = 11;
  CHANNEL_LEAVE_REQUEST = 12;
  CHANNEL_LEAVE_REPLY = 13;
  CHANNEL_MLS_COMMIT = 14;
  CHANNEL_MLS_WELCOME = 15;
  CHANNEL_MLS_PROPOSAL = 16;
  CHANNEL_MLS_ACK = 17;
}
// Session.session_id is the ID of the session

// Session.message_id meaning according to the SessionMessageType
// P2P_MSG = nonce
// P2P_RELIABLE = nonce
// P2P_ACK = nonce of the received P2P_RELIABLE message
// MULTICAST_MSG = sequential incremental ID per producer
// RTX_REQUEST = nonce
// RTX_REPLY = nonce of the associated RTX_REQUEST
// BEACON_MULTICAST = ID of the last message sent by the producer
// CHANNEL_DISCOVERY_REQUEST = nonce
// CHANNEL_DISCOVERY_REPLY = nonce of the associated CHANNEL_DISCOVERY_REQUEST
// CHANNEL_JOIN_REQUEST = nonce
// CHANNEL_JOIN_REPLY = nonce of the associated CHANNEL_JOIN_REQUEST
// CHANNEL_LEAVE_REQUEST = nonce
// CHANNEL_LEAVE_REPLY = nonce of the associated CHANNEL_LEAVE_REQUEST
// CHANNEL_MLS_COMMIT CHANNEL_MLS_WELCOME CHANNEL_MLS_PROPOSAL = nonce
// CHANNEL_MLS_ACK = nonce of the associated MLS message

message SessionHeader {
  SessionType session_type = 1;
  SessionMessageType session_message_type = 2;
  uint32 session_id = 3;
  uint32 message_id = 4;
  optional OriginalName source = 5;
  optional OriginalName destination = 6;
}

message Content {
  string content_type = 1;
  bytes blob = 2;
}

message Message {
  oneof messageType {
    Subscribe subscribe = 1;
    Unsubscribe unsubscribe = 2;
    Publish publish = 3;
  }
  map<string, string> metadata = 4;
}
