syntax = "proto3";

package pdpb;

// TSO Service
service Tso {
  rpc GetTimestamp(TsoRequest) returns (TsoResponse);
}

message TsoRequest {
  uint32 count = 1;
}

message TsoResponse {
  uint64 timestamp = 1; // Physical << 16 | Logical
  uint32 count = 2;
}

// Cluster Management Service
service Pd {
  // Store Registration
  rpc RegisterStore(RegisterStoreRequest) returns (RegisterStoreResponse);
  
  // Region Discovery
  rpc GetRegion(GetRegionRequest) returns (GetRegionResponse);
}

message RegisterStoreRequest {
  string addr = 1; // e.g., "127.0.0.1:50051"
}

message RegisterStoreResponse {
  uint64 store_id = 1;
  uint64 cluster_id = 2; // Verify cluster match
}

message GetRegionRequest {
  bytes key = 1;
}

message GetRegionResponse {
  Region region = 1;
  Store leader = 2;
}

message Region {
  uint64 id = 1;
  bytes start_key = 2;
  bytes end_key = 3; // empty = infinity
  // In future: repeated Peer peers = 4;
}

message Store {
  uint64 id = 1;
  string addr = 2;
}
