// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

syntax = "proto3";

package banyandb.schema.v1;

import "banyandb/model/v1/query.proto";
import "banyandb/property/v1/property.proto";
import "banyandb/property/v1/rpc.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/apache/skywalking-banyandb/api/proto/banyandb/schema/v1";
option java_package = "org.apache.skywalking.banyandb.schema.v1";

message InsertSchemaRequest {
  property.v1.Property property = 1;
}

message InsertSchemaResponse {}

message UpdateSchemaRequest {
  property.v1.Property property = 1;
}

message UpdateSchemaResponse {}

message ListSchemasRequest {
  property.v1.QueryRequest query = 1;
}

message ListSchemasResponse {
  repeated property.v1.Property properties = 1;
  // delete_times maps to properties in the same order.
  // 0 means not deleted, >0 means deletion timestamp.
  repeated int64 delete_times = 2;
}

message DeleteSchemaRequest {
  property.v1.DeleteRequest delete = 1;
  // Update the update time for notification
  google.protobuf.Timestamp update_at = 2;
}

message DeleteSchemaResponse {
  bool found = 1;
}

message RepairSchemaRequest {
  property.v1.Property property = 1;
  int64 delete_time = 2;
}

message RepairSchemaResponse {}

service SchemaManagementService {
  rpc InsertSchema(InsertSchemaRequest) returns (InsertSchemaResponse);
  rpc UpdateSchema(UpdateSchemaRequest) returns (UpdateSchemaResponse);
  rpc ListSchemas(ListSchemasRequest) returns (stream ListSchemasResponse);
  rpc DeleteSchema(DeleteSchemaRequest) returns (DeleteSchemaResponse);
  rpc RepairSchema(RepairSchemaRequest) returns (RepairSchemaResponse);
}

service SchemaUpdateService {
  rpc WatchSchemas(stream WatchSchemasRequest) returns (stream WatchSchemasResponse);
}

enum SchemaEventType {
  SCHEMA_EVENT_TYPE_UNSPECIFIED = 0;
  SCHEMA_EVENT_TYPE_INSERT = 1;
  SCHEMA_EVENT_TYPE_UPDATE = 2;
  SCHEMA_EVENT_TYPE_DELETE = 3;
  SCHEMA_EVENT_TYPE_REPLAY_DONE = 4;
}

message WatchSchemasRequest {
  model.v1.Criteria criteria = 1;
  repeated string tag_projection = 2;
}

message WatchSchemasResponse {
  SchemaEventType event_type = 1;
  property.v1.Property property = 2;
  bool metadata_only = 3;
  int64 delete_time = 4;
}
