syntax = "proto3";
package rockpaperscissors;
option go_package = "proto";

// https://cloud.google.com/service-management/reference/rpc/google.api#http
import "google/api/annotations.proto";

import "code.justin.tv/dta/rockpaperscissors/proto/event.proto";
import "code.justin.tv/dta/rockpaperscissors/proto/timerange.proto";

message AddEventRequest {
  Event event = 1;
}

message AddEventResponse {
}

message GetEventRequest {
  bytes uuid = 1;
  string encoded_uuid = 2;
}

message GetEventResponse {
  Event event = 1;
}

message QueryEventsRequest {
  TimeRange timerange = 1;

  string type = 2;

  // Deprecated: use AttributeFilters, instead.
  string project = 3 [deprecated=true];
  string developer = 4 [deprecated=true];

  message AttributeFilter {
    string key = 1;
    string value = 2;
  }
  repeated AttributeFilter filters = 5;
}

message QueryEventsResponse {
  repeated Event events = 1;
  int64 total_events = 2;
}

service EventService {
  // Directly add an Event to the datastore.
  // This skips any subscribers to the event bus.
  rpc AddEvent(AddEventRequest) returns (AddEventResponse) {
    option (google.api.http) = {
      post: "/api/v1/events"
      body: "*"
    };
  }

  // Get details of an Event.
  rpc GetEvent(GetEventRequest) returns (GetEventResponse) {
    option (google.api.http) = {
      get: "/api/v1/events/{encoded_uuid}"
    };
  }

  // Query for a list of Events.
  rpc QueryEvents(QueryEventsRequest) returns (QueryEventsResponse) {
    option (google.api.http) = {
      get: "/api/v1/events/types/{type}/{timerange.start.seconds}/{timerange.end.seconds}"
    };
  }
}
