syntax = "proto3";

package protocol.sdk.search.index_manager;
option csharp_namespace = "Couchbase.Grpc.Protocol.Sdk.Search.IndexManager";
option java_package = "com.couchbase.client.protocol.sdk.search.indexmanager";
option go_package = "github.com/couchbaselabs/transactions-fit-performer/protocol/sdk/search/index-manager";
option ruby_package = "FIT::Protocol::SDK::Search::IndexManager";
option java_multiple_files = true;

// Messages shared by sdk.management.search.proto and sdk.management.scope.search.proto.
// This is how they are shared in the SDKs as well.

message GetSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

message SearchIndex {
  string uuid = 1;
  string name = 2;
  string type = 3;
  string source_uuid = 5;
  string source_type = 7;

  // It's left intentionally ambiguous in the SDK-RFC how to represent these in the SDK.
  // For FIT, they should be converted into JSON.
  bytes params = 4;
  bytes source_params = 6;
  bytes plan_params = 8;
}

// Returns Result.index.
message GetIndex {
  string index_name = 1;
  optional GetSearchIndexOptions options = 2;
}

// Returns Result.indexes.
message GetAllIndexes {
  optional GetAllSearchIndexesOptions options = 1;
}

message GetAllSearchIndexesOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message UpsertIndex {
  // A JSON blob that the performer should use to create a SearchIndex.
  bytes index_definition = 1;
  optional UpsertSearchIndexOptions options = 2;
}

message UpsertSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message DropIndex {
  string index_name = 1;
  optional DropSearchIndexOptions options = 2;
}

message DropSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns Result.indexed_document_counts.
message GetIndexedDocumentsCount {
  string index_name = 1;
  optional GetIndexedSearchIndexOptions options = 2;
}

message GetIndexedSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message PauseIngest {
  string index_name = 1;
  optional PauseIngestSearchIndexOptions options = 2;
}

message PauseIngestSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message ResumeIngest {
  string index_name = 1;
  optional ResumeIngestSearchIndexOptions options = 2;
}

message ResumeIngestSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message AllowQuerying {
  string index_name = 1;
  optional AllowQueryingSearchIndexOptions options = 2;
}

message AllowQueryingSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message DisallowQuerying {
  string index_name = 1;
  optional DisallowQueryingSearchIndexOptions options = 2;
}

message DisallowQueryingSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message FreezePlan {
  string index_name = 1;
  optional FreezePlanSearchIndexOptions options = 2;
}

message FreezePlanSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns void (e.g. Result.success).
message UnfreezePlan {
  string index_name = 1;
  optional UnfreezePlanSearchIndexOptions options = 2;
}

message UnfreezePlanSearchIndexOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

// Returns Result.analyze_document;
message AnalyzeDocument {
  string index_name = 1;
  bytes document = 2;
  optional AnalyzeDocumentOptions options = 3;
}

message AnalyzeDocumentOptions {
  optional int32 timeout_msecs = 1;
  optional string parent_span_id = 2;
}

message AnalyzeDocumentResult {
  repeated bytes results = 1;
}

message SearchIndexes {
  repeated SearchIndex indexes = 1;
}

message Result {
  oneof result {
    // Used for void results.
    bool success = 1;
    SearchIndex index = 2;
    SearchIndexes indexes = 3;
    int32 indexed_document_counts = 4;
    AnalyzeDocumentResult analyze_document = 5;
  }
}

// These commands are shared between SearchIndexManager and ScopeSearchIndexManager.
// If API calls are added to just one of those, they should not go here.  Add them in
// scope.search.index_manager.Command or cluster.search.index_manager.Command instead.
message Command {
  oneof command {
    GetIndex get_index = 1;
    GetAllIndexes get_all_indexes = 2;
    UpsertIndex upsert_index = 3;
    DropIndex drop_index = 4;
    GetIndexedDocumentsCount get_indexed_documents_count = 5;
    PauseIngest pause_ingest = 6;
    ResumeIngest resume_ingest = 7;
    AllowQuerying allow_querying = 8;
    DisallowQuerying disallow_querying = 9;
    FreezePlan freeze_plan = 10;
    UnfreezePlan unfreeze_plan = 11;
    AnalyzeDocument analyze_document = 12;
  }
}
