syntax = "proto3";

import "collections.proto";

package qdrant;
option csharp_namespace = "Qdrant.Client.Grpc";

service CollectionsInternal {
  // Get collection info
  rpc Get(GetCollectionInfoRequestInternal)
      returns (GetCollectionInfoResponse) {}
  // Initiate shard transfer
  rpc Initiate(InitiateShardTransferRequest)
      returns (CollectionOperationResponse) {}
  // Wait for a shard to get into the given state
  rpc WaitForShardState(WaitForShardStateRequest)
      returns (CollectionOperationResponse) {}
  // Get shard recovery point
  rpc GetShardRecoveryPoint(GetShardRecoveryPointRequest)
      returns (GetShardRecoveryPointResponse) {}
  // Update shard cutoff point
  rpc UpdateShardCutoffPoint(UpdateShardCutoffPointRequest)
      returns (CollectionOperationResponse) {}
  // Get shard optimizations info
  rpc GetShardOptimizations(GetShardOptimizationsRequest)
      returns (GetShardOptimizationsResponse) {}
}

message GetCollectionInfoRequestInternal {
  GetCollectionInfoRequest get_collectionInfoRequest = 1;
  uint32 shard_id = 2;
}

message InitiateShardTransferRequest {
  // Name of the collection
  string collection_name = 1;
  // Id of the temporary shard
  uint32 shard_id = 2;
}

message WaitForShardStateRequest {
  // Name of the collection
  string collection_name = 1;
  // Id of the shard
  uint32 shard_id = 2;
  // Shard state to wait for
  ReplicaState state = 3;
  // Timeout in seconds
  uint64 timeout = 4;
}

message GetShardRecoveryPointRequest {
  // Name of the collection
  string collection_name = 1;
  // Id of the shard
  uint32 shard_id = 2;
}

message GetShardRecoveryPointResponse {
  // Recovery point of the shard
  RecoveryPoint recovery_point = 1;
  // Time spent to process
  double time = 2;
}

message RecoveryPoint {
  repeated RecoveryPointClockTag clocks = 1;
}

message RecoveryPointClockTag {
  uint64 peer_id = 1;
  uint32 clock_id = 2;
  uint64 clock_tick = 3;
  uint64 token = 4;
}

message UpdateShardCutoffPointRequest {
  // Name of the collection
  string collection_name = 1;
  // Id of the shard
  uint32 shard_id = 2;
  // Cutoff point of the shard
  RecoveryPoint cutoff = 3;
}

message GetShardOptimizationsRequest {
  // Name of the collection
  string collection_name = 1;
  // Id of the shard
  uint32 shard_id = 2;
  // Whether to include queued optimizations
  bool with_queued = 3;
  // Limit for completed optimizations (0 means not included)
  optional uint32 completed_limit = 4;
  // Whether to include idle segments
  bool with_idle_segments = 5;
}

message GetShardOptimizationsResponse {
  // JSON-serialized OptimizationsResponse
  bytes optimizations_json = 1;
  // Time spent to process
  double time = 2;
}
