syntax = "proto3";

import "gogo/protobuf/gogoproto/gogo.proto";
import "protobuf/types/struct.proto";
import "protobuf/types/event.proto";

package mesg.api;
option go_package = "api";

// This is the API to interact with the Events.
//
// This API is a [gRPC](https://grpc.io/) API.
//
// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/engine/blob/master/protobuf/api/event.proto).
service Event {
  // Create creates event with data.
  rpc Create(CreateEventRequest) returns (CreateEventResponse) {}

  // Stream returns a stream of events that satisfy criteria
  // specified in a request.
  rpc Stream(StreamEventRequest) returns (stream types.Event) {}
}

// StreamEventRequest defines request to retrieve a stream of events.
message StreamEventRequest {
  // Filter contains filtering criteria.
  message Filter {
    // hash to filter events.
    bytes hash = 1 [
      (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
      (gogoproto.nullable) = false
    ];

    // instance's hash to filter events.
    bytes instanceHash = 2 [
      (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
      (gogoproto.nullable) = false
    ];

    // key is the key of the event.
    string key = 3;
  }

  // Filter used to filter a stream of events.
  Filter filter = 1;
}

// CreateEventRequest defines request for execution update.
message CreateEventRequest {
  // instanceHash is hash of instance that can proceed an execution.
  bytes instanceHash = 1 [
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];

  // key is the key of the event.
  string key = 2;

  // data is the data for the event.
  mesg.protobuf.Struct data = 3;
}

// CreateEventResponse defines response for execution update.
message CreateEventResponse {
  // Hash represents event.
  bytes hash = 1 [
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];
}
