syntax = "proto3";

package galaxy.gateway.v1;

option go_package = "galaxy/gateway/proto/galaxy/gateway/v1;gatewayv1";

import "buf/validate/validate.proto";

service EdgeGateway {
  rpc ExecuteCommand(ExecuteCommandRequest) returns (ExecuteCommandResponse);
  rpc SubscribeEvents(SubscribeEventsRequest) returns (stream GatewayEvent);
}

message ExecuteCommandRequest {
  // protocol_version identifies the request envelope version. The gateway
  // accepts only the literal "v1" after required-field validation succeeds.
  string protocol_version = 1 [(buf.validate.field).string.min_len = 1];
  string device_session_id = 2 [(buf.validate.field).string.min_len = 1];
  string message_type = 3 [(buf.validate.field).string.min_len = 1];
  int64 timestamp_ms = 4 [(buf.validate.field).int64.gt = 0];
  string request_id = 5 [(buf.validate.field).string.min_len = 1];
  bytes payload_bytes = 6 [(buf.validate.field).bytes.min_len = 1];
  // payload_hash is the raw 32-byte SHA-256 digest of payload_bytes.
  bytes payload_hash = 7 [(buf.validate.field).bytes.min_len = 1];
  bytes signature = 8 [(buf.validate.field).bytes.min_len = 1];
  string trace_id = 9;
}

message ExecuteCommandResponse {
  string protocol_version = 1;
  string request_id = 2;
  int64 timestamp_ms = 3;
  string result_code = 4;
  bytes payload_bytes = 5;
  bytes payload_hash = 6;
  bytes signature = 7;
}

message SubscribeEventsRequest {
  // protocol_version identifies the request envelope version. The gateway
  // accepts only the literal "v1" after required-field validation succeeds.
  string protocol_version = 1 [(buf.validate.field).string.min_len = 1];
  string device_session_id = 2 [(buf.validate.field).string.min_len = 1];
  string message_type = 3 [(buf.validate.field).string.min_len = 1];
  int64 timestamp_ms = 4 [(buf.validate.field).int64.gt = 0];
  string request_id = 5 [(buf.validate.field).string.min_len = 1];
  // payload_hash is the raw 32-byte SHA-256 digest of payload_bytes. Empty
  // payloads must use the SHA-256 digest of the empty byte slice.
  bytes payload_hash = 6 [(buf.validate.field).bytes.min_len = 1];
  bytes signature = 7 [(buf.validate.field).bytes.min_len = 1];
  bytes payload_bytes = 8;
  string trace_id = 9;
}

message GatewayEvent {
  string event_type = 1;
  string event_id = 2;
  int64 timestamp_ms = 3;
  bytes payload_bytes = 4;
  bytes payload_hash = 5;
  bytes signature = 6;
  string request_id = 7;
  string trace_id = 8;
}
