syntax = "proto3";

import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";

import "DeploymentEvent.proto";
import "EnvironmentEvent.proto";
import "EventLogsExtensions.proto";

package Klang.Seed.Services.EventLogs;

service EventLogsService {
  rpc EventStream(stream EventBatchRequest) returns (EventStreamResponse);
  rpc EventBatch(EventBatchRequest) returns (EventBatchResponse);
  rpc GetStatus(GetStatusRequest) returns (GetStatusResponse);
}

// Service types
message EventStreamResponse {
  int64 messagesSaved = 1;
  int64 lastIndexSaved = 2;
}

message GetStatusRequest {}

message GetStatusResponse {
  bool ok = 1;
}

message EventBatchRequest {
  repeated Event events = 1;
}

message EventBatchResponse {int32 messagesSaved = 1;}

message Event {
  option (Klang.Seed.Services.EventLogs.Extensions.EventVersionDefaultValue) = 1;
  int64 eventIndex = 1;
  string sessionId = 2;
  google.protobuf.Timestamp eventTimestamp = 3;
  string worldName = 4;
  string sectorName = 5;
  int32 eventVersion = 6;
  string environmentName = 7;
  string eventId = 8;
  google.protobuf.Struct payload = 9;
  
  // Unique identifier of a world deployment
  string worldId = 20;

  // Full project version string in SemVer format
  string projectVersion = 30;
  // Project version as individual numeric fields for easier sorting
  int32 projectVersionMajor = 31;
  int32 projectVersionMinor = 32;
  int32 projectVersionPatch = 33;

  oneof categoryType {
    Deployment.Event deploymentEvent = 1000;
    Environment.Event environmentEvent = 1001;
  }
}

// Simple message used for the unit tests
message TestEventLogMessage {
  google.protobuf.Timestamp when = 1;
  int64 noOption = 2;
  int64 withTypeAndNameOverride = 3 [(Extensions.BigQueryFieldType) = Float64, (Extensions.BigQueryFieldName) = "name_override"];
}
