syntax = "proto3";

package code.justin.tv.eventbus.controlplane;
option go_package = "rpc";

import "github.com/golang/protobuf/ptypes/timestamp/timestamp.proto";
import "github.com/golang/protobuf/ptypes/wrappers/wrappers.proto";

service EventStreams {
  // List the event streams available in the system. Does not include statistics.
  rpc List(ListEventStreamsReq) returns (ListEventStreamsResp);

  // Get details of a single event stream
  rpc Get(GetEventStreamReq) returns (EventStream);

  // Get usage statistics for a stream
  rpc GetStats(GetEventStreamStatsReq) returns (EventStreamStats);
}

service EventTypes {
  // List the event types available in the system.
  rpc List(ListEventTypesReq) returns (ListEventTypesResp);
}

message EventType {
  string id = 1;
  string name = 2;
  string description = 3;
  string repo_filepath = 4;
  bool deprecated = 5;
  string ldap_group = 6;
}

message ListEventTypesReq {
  // Optional fields used for filtering
  string ldap_group = 1;
}

message ListEventTypesResp {
  repeated EventType event_types = 1;
}

message ListEventStreamsReq {
  string cursor = 1; // If provided, should be a cursor given by `next_cursor` from a previous call.
  // In the future we may have filter options for listing event streams
  // TODO: add support for filtering on environment using optional environment string field
}

message ListEventStreamsResp {
  repeated EventStream event_streams = 1;

  // If next_cursor is returned, it is an opaque string to get the next page of results
  string next_cursor = 2;
}

message GetEventStreamReq {
  string event_type = 1;
  string environment = 2;
}

message GetEventStreamStatsReq {
  string event_type = 1;
  string environment = 2;
}

message EventStream {
  string event_type = 1; // A canonical event ID, e.g. "ClockTick"
  string environment = 2; // The environment for which this stream exists, e.g. production, staging, development

  string display_name = 3; // Display name; currently the same as the id
  string short_description = 4; // Short description, usually 2 sentences or less.
  google.protobuf.Timestamp active_since = 5; // When this event stream was first created, if known.
  string description = 6; // Long description. May contain markdown-formatted paragraphs and links.
  EventStreamStats stats = 7;   // If available, statistics on this event stream.
  string schema = 8; // The plaintext content of the protobuf file for this event type
  string repo_filepath = 9; // The path to the proto file in the repo
  repeated AuthorizedField authorized_fields = 10; // the authorized fields for this EventStream, which require authorization to access
  bool deprecated = 11; // true if the underlying event type has been marked as deprecated by publisher
  string ldap_group = 12; // The LDAP Group that manages permissions for this event type
}

// EventStreamStats gives some basic stats about the event.
// We use wrapper types here so that we can meaningfully provide 'null' values
// for stats we do not currently know.
message EventStreamStats {
  google.protobuf.DoubleValue tps_mean = 1 [deprecated=true]; // UNUSED Average event rate, measured in events per minute
  google.protobuf.DoubleValue tps_95th = 2 [deprecated=true]; // UNUSED 95th percentile TPS

  google.protobuf.DoubleValue mean_events_per_minute = 3; // Mean event rate, measured in events per minute
  google.protobuf.DoubleValue max_events_per_minute = 4; // Max event rate, measured in events per minute
  google.protobuf.DoubleValue min_events_per_minute = 5; // Min event rate, measured in events per minute
  google.protobuf.DoubleValue mean_event_payload_size = 6; // Average event payload size, measured in bytes
  uint32 publisher_count = 7 [deprecated=true];
  uint32 subscriber_count = 8 [deprecated=true];
  repeated PublisherServiceInfo publishers = 9;
}

message PublisherServiceInfo {
  string name = 1;
  string service_catalog_url = 2;
}

message AuthorizedField {
  string message_name = 1;
  string field_name = 2;
}
