syntax = "proto3";

package rpcdb;

import "google/protobuf/empty.proto";

option go_package = "github.com/ava-labs/avalanchego/proto/pb/rpcdb";

service Database {
  rpc Has(HasRequest) returns (HasResponse);
  rpc Get(GetRequest) returns (GetResponse);
  rpc Put(PutRequest) returns (PutResponse);
  rpc Delete(DeleteRequest) returns (DeleteResponse);
  rpc Compact(CompactRequest) returns (CompactResponse);
  rpc Close(CloseRequest) returns (CloseResponse);
  rpc HealthCheck(google.protobuf.Empty) returns (HealthCheckResponse);
  rpc WriteBatch(WriteBatchRequest) returns (WriteBatchResponse);
  rpc NewIteratorWithStartAndPrefix(NewIteratorWithStartAndPrefixRequest) returns (NewIteratorWithStartAndPrefixResponse);
  rpc IteratorNext(IteratorNextRequest) returns (IteratorNextResponse);
  rpc IteratorError(IteratorErrorRequest) returns (IteratorErrorResponse);
  rpc IteratorRelease(IteratorReleaseRequest) returns (IteratorReleaseResponse);
}

enum Error {
  // ERROR_UNSPECIFIED is used to indicate that no error occurred.
  ERROR_UNSPECIFIED = 0;
  ERROR_CLOSED = 1;
  ERROR_NOT_FOUND = 2;
}

message HasRequest {
  bytes key = 1;
}

message HasResponse {
  bool has = 1;
  Error err = 2;
}

message GetRequest {
  bytes key = 1;
}

message GetResponse {
  bytes value = 1;
  Error err = 2;
}

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

message PutResponse {
  Error err = 1;
}

message DeleteRequest {
  bytes key = 1;
}

message DeleteResponse {
  Error err = 1;
}

message CompactRequest {
  bytes start = 1;
  bytes limit = 2;
}

message CompactResponse {
  Error err = 1;
}

message CloseRequest {}

message CloseResponse {
  Error err = 1;
}

message WriteBatchRequest {
  repeated PutRequest puts = 1;
  repeated DeleteRequest deletes = 2;
}

message WriteBatchResponse {
  Error err = 1;
}

message NewIteratorRequest {}

message NewIteratorWithStartAndPrefixRequest {
  bytes start = 1;
  bytes prefix = 2;
}

message NewIteratorWithStartAndPrefixResponse {
  uint64 id = 1;
}

message IteratorNextRequest {
  uint64 id = 1;
}

message IteratorNextResponse {
  repeated PutRequest data = 1;
}

message IteratorErrorRequest {
  uint64 id = 1;
}

message IteratorErrorResponse {
  Error err = 1;
}

message IteratorReleaseRequest {
  uint64 id = 1;
}

message IteratorReleaseResponse {
  Error err = 1;
}

message HealthCheckResponse {
  bytes details = 1;
}
