syntax = "proto3";

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

service Subscriptions {
  rpc Create(CreateSubscriptionReq) returns (CreateSubscriptionResp);
  rpc Delete(DeleteSubscriptionReq) returns (DeleteSubscriptionResp);
  rpc GetSubscriptionsForTarget(GetSubscriptionsForTargetReq) returns (GetSubscriptionsForTargetResp);
}

message Subscription {
  string target_id = 1; // The target the subscription is for
  string event_type = 2; // The event being subscribed to the target
  string id = 3; // The ID of this subscription (generated by server)

  SubscriptionStatus status = 4; // Indicates the state of the subscription currently
  string message = 5; // in the case of errors, use this field to relay contextual error information

  string environment = 6; // the environment of the stream to subscribe to
}

message CreateSubscriptionReq {
    string target_id = 1;
    string event_type = 2;
    string environment = 3;
}
message CreateSubscriptionResp {
    Subscription subscription = 1;
}

message DeleteSubscriptionReq {
    string target_id = 1;
    string event_type = 2;
    string environment = 3;
}
message DeleteSubscriptionResp {}

message GetSubscriptionsForTargetReq {
    string target_id = 1;
}
message GetSubscriptionsForTargetResp {
    repeated Subscription subscriptions = 2;
}

// The dashboard can use this information to report the state of the Subscription to the user
enum SubscriptionStatus {
  SUBSCRIPTION_STATUS_UNKNOWN = 0; // Mask out the zero value
  SUBSCRIPTION_STATUS_DISABLED = 1; // Subscription is disable (no events flowing)
  SUBSCRIPTION_STATUS_ENABLED = 2; // Subscription is enabled (events flowing)
  SUBSCRIPTION_STATUS_PENDING_DISABLE = 3; // Subscription is enabled, pending being disabled by converger
  SUBSCRIPTION_STATUS_PENDING_ENABLE = 4; // Subscription is disabled, pending being enabled by converger
  SUBSCRIPTION_STATUS_ERROR_DISABLE = 5; // Subscription is in an error state trying to enable
  SUBSCRIPTION_STATUS_ERROR_ENABLE = 6; // Subscription is in an error state trying to disable
  SUBSCRIPTION_STATUS_ERROR_CREATE = 7; // Subscription is in an error state attempting to provision link between target and eventstream
  SUBSCRIPTION_STATUS_PENDING_DELETE = 8; // Subscription has been flagged for deletion, pending the converger cleaning it up and removing it from the database
  SUBSCRIPTION_STATUS_ERROR_DELETE = 9; // Subscription is in an error state trying to delete
}

