// Copyright 2023 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package internal;
option go_package = "github.com/livekit/psrpc/internal";

import "google/protobuf/any.proto";

message Msg {
  string type_url = 1;
  bytes value = 2;
  string channel = 3;
}

message Channel {
  string channel = 3;
}

message Request {
  string request_id = 1;
  string client_id = 2;
  int64 sent_at = 3;
  int64 expiry = 4;
  bool multi = 5;
  google.protobuf.Any request = 6;
  map<string, string> metadata = 7;
  bytes raw_request = 8;
}

message Response {
  string request_id = 1;
  string server_id = 2;
  int64 sent_at = 3;
  google.protobuf.Any response = 4;
  string error = 5;
  string code = 6;
  bytes raw_response = 7;
  repeated google.protobuf.Any error_details = 8;
}

message ClaimRequest {
  string request_id = 1;
  string server_id = 2;
  float affinity = 3;
}

message ClaimResponse {
  string request_id = 1;
  string server_id = 2;
}

message Stream {
  string stream_id = 1;
  string request_id = 2;
  int64 sent_at = 3;
  int64 expiry = 4;
  oneof body {
    StreamOpen open = 6;
    StreamMessage message = 7;
    StreamAck ack = 8;
    StreamClose close = 9;
  }
}

message StreamOpen {
  string node_id = 1;
  map<string, string> metadata = 7;
}

message StreamMessage {
  google.protobuf.Any message = 1;
  bytes raw_message = 2;
}

message StreamAck {}

message StreamClose {
  string error = 1;
  string code = 2;
}
