syntax = "proto3";

package eventdbx.api;

message HealthRequest {}

message HealthResponse {
  string status = 1;
}

message AppendEventRequest {
  string aggregate_type = 1;
  string aggregate_id = 2;
  string event_type = 3;
  string payload_json = 4;
}

message AppendEventResponse {
  Event event = 1;
}

message ListAggregatesRequest {
  uint32 skip = 1;
  uint32 take = 2;
}

message ListAggregatesResponse {
  repeated Aggregate aggregates = 1;
}

message GetAggregateRequest {
  string aggregate_type = 1;
  string aggregate_id = 2;
}

message GetAggregateResponse {
  Aggregate aggregate = 1;
}

message ListEventsRequest {
  string aggregate_type = 1;
  string aggregate_id = 2;
  uint32 skip = 3;
  uint32 take = 4;
}

message ListEventsResponse {
  repeated Event events = 1;
}

message VerifyAggregateRequest {
  string aggregate_type = 1;
  string aggregate_id = 2;
}

message VerifyAggregateResponse {
  string merkle_root = 1;
}

message Aggregate {
  string aggregate_type = 1;
  string aggregate_id = 2;
  uint64 version = 3;
  map<string, string> state = 4;
  string merkle_root = 5;
  bool archived = 6;
}

message Event {
  string aggregate_type = 1;
  string aggregate_id = 2;
  string event_type = 3;
  uint64 version = 4;
  string payload_json = 5;
  EventMetadata metadata = 6;
  string hash = 7;
  string merkle_root = 8;
}

message EventMetadata {
  string event_id = 1;
  string created_at = 2;
  ActorClaims issued_by = 3;
}

message ActorClaims {
  string group = 1;
  string user = 2;
}

service EventService {
  rpc Health(HealthRequest) returns (HealthResponse);
  rpc AppendEvent(AppendEventRequest) returns (AppendEventResponse);
  rpc ListAggregates(ListAggregatesRequest) returns (ListAggregatesResponse);
  rpc GetAggregate(GetAggregateRequest) returns (GetAggregateResponse);
  rpc ListEvents(ListEventsRequest) returns (ListEventsResponse);
  rpc VerifyAggregate(VerifyAggregateRequest) returns (VerifyAggregateResponse);
}
