syntax = "proto3";

package chroma;
option go_package = "github.com/chroma-core/chroma/go/pkg/proto/logservicepb";

import "chromadb/proto/chroma.proto";

message PushLogsRequest {
  string collection_id = 1;
  repeated OperationRecord records = 2;
}

message PushLogsResponse {
  int32 record_count = 1;
}

message PullLogsRequest {
  string collection_id = 1;
  int64 start_from_offset = 2;
  int32 batch_size = 3;
  int64 end_timestamp = 4;
}

// Represents an operation from the log
message LogRecord {
  int64 log_offset = 1;
  OperationRecord record = 2;
}

message PullLogsResponse {
  repeated LogRecord records = 1;
}

message CollectionInfo {
  string collection_id = 1;
  // The log offset of the first log entry of the collection that needs to be compacted
  int64 first_log_offset = 2;
  // The timestamp of the first log entry of the collection that needs to be compacted
  int64 first_log_ts = 3;
}

message GetAllCollectionInfoToCompactRequest {
  // The minimum number of log entries that a collection should have before it should
  // be returned for compaction
  uint64 min_compaction_size = 1;
}

message GetAllCollectionInfoToCompactResponse {
  repeated CollectionInfo all_collection_info = 1;
}

message UpdateCollectionLogOffsetRequest {
  string collection_id = 1;
  int64 log_offset = 2;
}

message UpdateCollectionLogOffsetResponse {
  // Empty
}

message PurgeDirtyForCollectionRequest {
  string collection_id = 1;
}

message PurgeDirtyForCollectionResponse {
  // Empty
}

service LogService {
  rpc PushLogs(PushLogsRequest) returns (PushLogsResponse) {}
  rpc PullLogs(PullLogsRequest) returns (PullLogsResponse) {}
  rpc GetAllCollectionInfoToCompact(GetAllCollectionInfoToCompactRequest) returns (GetAllCollectionInfoToCompactResponse) {}
  rpc UpdateCollectionLogOffset(UpdateCollectionLogOffsetRequest) returns (UpdateCollectionLogOffsetResponse) {}
  rpc PurgeDirtyForCollection(PurgeDirtyForCollectionRequest) returns (PurgeDirtyForCollectionResponse) {}
}
