// 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.pipeline.v1;

import "banyandb/common/v1/common.proto";
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
import "validate/validate.proto";

option go_package = "github.com/apache/skywalking-banyandb/api/proto/banyandb/pipeline/v1";
option java_package = "org.apache.skywalking.banyandb.pipeline.v1";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {base_path: "/api"};

message TracePipelineRegistryServiceCreateRequest {
  common.v1.TracePipelineConfig trace_pipeline_config = 1 [(validate.rules).message = {required: true}];
}

message TracePipelineRegistryServiceCreateResponse {
  int64 mod_revision = 1;
}

message TracePipelineRegistryServiceUpdateRequest {
  common.v1.TracePipelineConfig trace_pipeline_config = 1 [(validate.rules).message = {required: true}];
}

message TracePipelineRegistryServiceUpdateResponse {
  int64 mod_revision = 1;
}

message TracePipelineRegistryServiceDeleteRequest {
  common.v1.Metadata metadata = 1 [(validate.rules).message = {required: true}];
}

message TracePipelineRegistryServiceDeleteResponse {
  bool deleted = 1;
  // delete_time is the server-assigned tombstone timestamp in unix nanos.
  int64 delete_time = 2;
  // mod_revision is the revision of the tombstone; zero if the server did not record one.
  int64 mod_revision = 3;
}

message TracePipelineRegistryServiceGetRequest {
  common.v1.Metadata metadata = 1 [(validate.rules).message = {required: true}];
}

message TracePipelineRegistryServiceGetResponse {
  common.v1.TracePipelineConfig trace_pipeline_config = 1;
}

message TracePipelineRegistryServiceExistRequest {
  common.v1.Metadata metadata = 1 [(validate.rules).message = {required: true}];
}

message TracePipelineRegistryServiceExistResponse {
  bool has_group = 1;
  bool has_trace_pipeline_config = 2;
}

message TracePipelineRegistryServiceListRequest {
  string group = 1 [(validate.rules).string.min_len = 1];
}

message TracePipelineRegistryServiceListResponse {
  repeated common.v1.TracePipelineConfig trace_pipeline_config = 1;
}

// TracePipelineRegistryService manages TracePipelineConfig resources, mirroring
// the registry services of every other schema resource. Create/Update run the
// admission and conflict checks of §2.3/§2.4 of the design.
service TracePipelineRegistryService {
  rpc Create(TracePipelineRegistryServiceCreateRequest) returns (TracePipelineRegistryServiceCreateResponse) {
    option (google.api.http) = {
      post: "/v1/trace-pipeline/schema"
      body: "*"
    };
  }

  rpc Update(TracePipelineRegistryServiceUpdateRequest) returns (TracePipelineRegistryServiceUpdateResponse) {
    option (google.api.http) = {
      put: "/v1/trace-pipeline/schema"
      body: "*"
    };
  }

  rpc Delete(TracePipelineRegistryServiceDeleteRequest) returns (TracePipelineRegistryServiceDeleteResponse) {
    option (google.api.http) = {delete: "/v1/trace-pipeline/schema/{metadata.group}/{metadata.name}"};
  }

  rpc Get(TracePipelineRegistryServiceGetRequest) returns (TracePipelineRegistryServiceGetResponse) {
    option (google.api.http) = {get: "/v1/trace-pipeline/schema/{metadata.group}/{metadata.name}"};
  }

  rpc List(TracePipelineRegistryServiceListRequest) returns (TracePipelineRegistryServiceListResponse) {
    option (google.api.http) = {get: "/v1/trace-pipeline/schema/lists/{group}"};
  }

  // Exist doesn't expose an HTTP endpoint. Please use HEAD method to touch Get instead.
  rpc Exist(TracePipelineRegistryServiceExistRequest) returns (TracePipelineRegistryServiceExistResponse);
}
