syntax = "proto3";

package kvrpc;

// Raw (Eventual Consistency) Operations
service KvRaw {
  rpc RawPut(RawPutRequest) returns (RawPutResponse);
  rpc RawGet(RawGetRequest) returns (RawGetResponse);
}

message RawPutRequest {
  bytes key = 1;
  bytes value = 2;
}

message RawPutResponse {
  bool success = 1;
}

message RawGetRequest {
  bytes key = 1;
}

message RawGetResponse {
  bool found = 1;
  bytes value = 2;
}

// CAS (Strong Consistency / Optimistic) Operations
service KvCas {
  rpc CompareAndSwap(CasRequest) returns (CasResponse);
  rpc Get(GetRequest) returns (GetResponse);
}

message CasRequest {
  bytes key = 1;
  bytes value = 2;
  uint64 expected_version = 3; // 0 implies "create if not exists"
}

message CasResponse {
  bool success = 1;
  uint64 current_version = 2; // Returns current version on failure (for retry)
  uint64 new_version = 3;     // Returns assigned version on success
}

message GetRequest {
  bytes key = 1;
}

message GetResponse {
  bool found = 1;
  bytes value = 2;
  uint64 version = 3;
}
