syntax = "proto3";

package nodewriter;

import public "nidx_protos/noderesources.proto";


message OpStatus {
    enum Status {
        OK = 0;
        WARNING = 1;
        ERROR = 2;
    }
    Status status = 1;
    string detail = 2;

    uint64 field_count = 3 [deprecated = true];
    uint64 paragraph_count = 5 [deprecated = true];
    uint64 sentence_count = 6 [deprecated = true];
    string shard_id = 4 [deprecated = true];
}

// Implemented at nucliadb_object_storage

enum TypeMessage {
    CREATION = 0;
    DELETION = 1;
}

enum IndexMessageSource {
    PROCESSOR = 0;
    WRITER = 1;
}

message IndexMessage {
    string node = 1;
    string shard = 2;  // physical shard message is for
    uint64 txid = 3;
    string resource = 4;
    TypeMessage typemessage = 5;
    string reindex_id = 6;
    optional string partition = 7;
    string storage_key = 8;
    string kbid = 9;
    IndexMessageSource source = 10;
}

message GarbageCollectorResponse {
    enum Status {
        OK = 0;
        TRY_LATER = 1;
    }
    Status status = 1;
}

enum VectorType {
    DENSE_F32 = 0;
}

message VectorIndexConfig {
    utils.VectorSimilarity similarity = 1;
    bool normalize_vectors = 2;
    VectorType vector_type = 3;
    optional uint32 vector_dimension = 4;
}

message NewShardRequest {
    utils.VectorSimilarity similarity = 1 [deprecated = true];
    string kbid = 2;
    utils.ReleaseChannel release_channel = 3;
    // indicates whether the shard should normalize vectors on indexing or not
    bool normalize_vectors = 4 [deprecated = true];
    VectorIndexConfig config = 5 [deprecated = true];
    map<string, VectorIndexConfig> vectorsets_configs = 6;

}

message NewVectorSetRequest {
    noderesources.VectorSetID id = 1;
    utils.VectorSimilarity similarity = 2 [deprecated = true];
    bool normalize_vectors = 3 [deprecated = true];
    VectorIndexConfig config = 4;
}

message MergeResponse {
    enum MergeStatus {
        OK = 0;
    }
    MergeStatus status = 1;
    uint32 merged_segments = 2;
    uint32 remaining_segments = 3;
}

service NodeWriter {
    rpc NewShard(NewShardRequest) returns (noderesources.ShardCreated) {}
    rpc DeleteShard(noderesources.ShardId) returns (noderesources.ShardId) {}
    rpc ListShards(noderesources.EmptyQuery) returns (noderesources.ShardIds) {}
    rpc GC(noderesources.ShardId) returns (GarbageCollectorResponse) {}
    rpc Merge(noderesources.ShardId) returns (MergeResponse) {}

    rpc SetResource(noderesources.Resource) returns (OpStatus) {}
    rpc SetResourceFromStorage(IndexMessage) returns (OpStatus) {}
    rpc RemoveResource(noderesources.ResourceID) returns (OpStatus) {}

    rpc AddVectorSet(NewVectorSetRequest) returns (OpStatus) {}  // New
    rpc RemoveVectorSet(noderesources.VectorSetID) returns (OpStatus) {}
    rpc ListVectorSets(noderesources.ShardId) returns (noderesources.VectorSetList) {}

    rpc GetMetadata(noderesources.EmptyQuery) returns (noderesources.NodeMetadata) {}
}
