// Copyright 2025 Google LLC
//
// Licensed 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
//
//      https://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.

// Generated by the Codegen C++ plugin.
// If you make any local changes, they will be lost.
// source: google/cloud/chronicle/v1/rule.proto

#include "google/cloud/chronicle/v1/internal/rule_tracing_connection.h"
#include "google/cloud/internal/opentelemetry.h"
#include "google/cloud/internal/traced_stream_range.h"
#include <memory>
#include <utility>

namespace google {
namespace cloud {
namespace chronicle_v1_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY

RuleServiceTracingConnection::RuleServiceTracingConnection(
    std::shared_ptr<chronicle_v1::RuleServiceConnection> child)
    : child_(std::move(child)) {}

StatusOr<google::cloud::chronicle::v1::Rule>
RuleServiceTracingConnection::CreateRule(
    google::cloud::chronicle::v1::CreateRuleRequest const& request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::CreateRule");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->CreateRule(request));
}

StatusOr<google::cloud::chronicle::v1::Rule>
RuleServiceTracingConnection::GetRule(
    google::cloud::chronicle::v1::GetRuleRequest const& request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::GetRule");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->GetRule(request));
}

StreamRange<google::cloud::chronicle::v1::Rule>
RuleServiceTracingConnection::ListRules(
    google::cloud::chronicle::v1::ListRulesRequest request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::ListRules");
  internal::OTelScope scope(span);
  auto sr = child_->ListRules(std::move(request));
  return internal::MakeTracedStreamRange<google::cloud::chronicle::v1::Rule>(
      std::move(span), std::move(sr));
}

StatusOr<google::cloud::chronicle::v1::Rule>
RuleServiceTracingConnection::UpdateRule(
    google::cloud::chronicle::v1::UpdateRuleRequest const& request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::UpdateRule");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->UpdateRule(request));
}

Status RuleServiceTracingConnection::DeleteRule(
    google::cloud::chronicle::v1::DeleteRuleRequest const& request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::DeleteRule");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->DeleteRule(request));
}

StreamRange<google::cloud::chronicle::v1::Rule>
RuleServiceTracingConnection::ListRuleRevisions(
    google::cloud::chronicle::v1::ListRuleRevisionsRequest request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::ListRuleRevisions");
  internal::OTelScope scope(span);
  auto sr = child_->ListRuleRevisions(std::move(request));
  return internal::MakeTracedStreamRange<google::cloud::chronicle::v1::Rule>(
      std::move(span), std::move(sr));
}

future<StatusOr<google::cloud::chronicle::v1::Retrohunt>>
RuleServiceTracingConnection::CreateRetrohunt(
    google::cloud::chronicle::v1::CreateRetrohuntRequest const& request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::CreateRetrohunt");
  internal::OTelScope scope(span);
  return internal::EndSpan(std::move(span), child_->CreateRetrohunt(request));
}

StatusOr<google::longrunning::Operation>
RuleServiceTracingConnection::CreateRetrohunt(
    NoAwaitTag,
    google::cloud::chronicle::v1::CreateRetrohuntRequest const& request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::CreateRetrohunt");
  opentelemetry::trace::Scope scope(span);
  return internal::EndSpan(*span,
                           child_->CreateRetrohunt(NoAwaitTag{}, request));
}

future<StatusOr<google::cloud::chronicle::v1::Retrohunt>>
RuleServiceTracingConnection::CreateRetrohunt(
    google::longrunning::Operation const& operation) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::CreateRetrohunt");
  internal::OTelScope scope(span);
  return internal::EndSpan(std::move(span), child_->CreateRetrohunt(operation));
}

StatusOr<google::cloud::chronicle::v1::Retrohunt>
RuleServiceTracingConnection::GetRetrohunt(
    google::cloud::chronicle::v1::GetRetrohuntRequest const& request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::GetRetrohunt");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->GetRetrohunt(request));
}

StreamRange<google::cloud::chronicle::v1::Retrohunt>
RuleServiceTracingConnection::ListRetrohunts(
    google::cloud::chronicle::v1::ListRetrohuntsRequest request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::ListRetrohunts");
  internal::OTelScope scope(span);
  auto sr = child_->ListRetrohunts(std::move(request));
  return internal::MakeTracedStreamRange<
      google::cloud::chronicle::v1::Retrohunt>(std::move(span), std::move(sr));
}

StatusOr<google::cloud::chronicle::v1::RuleDeployment>
RuleServiceTracingConnection::GetRuleDeployment(
    google::cloud::chronicle::v1::GetRuleDeploymentRequest const& request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::GetRuleDeployment");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->GetRuleDeployment(request));
}

StreamRange<google::cloud::chronicle::v1::RuleDeployment>
RuleServiceTracingConnection::ListRuleDeployments(
    google::cloud::chronicle::v1::ListRuleDeploymentsRequest request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::ListRuleDeployments");
  internal::OTelScope scope(span);
  auto sr = child_->ListRuleDeployments(std::move(request));
  return internal::MakeTracedStreamRange<
      google::cloud::chronicle::v1::RuleDeployment>(std::move(span),
                                                    std::move(sr));
}

StatusOr<google::cloud::chronicle::v1::RuleDeployment>
RuleServiceTracingConnection::UpdateRuleDeployment(
    google::cloud::chronicle::v1::UpdateRuleDeploymentRequest const& request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::UpdateRuleDeployment");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->UpdateRuleDeployment(request));
}

StreamRange<google::longrunning::Operation>
RuleServiceTracingConnection::ListOperations(
    google::longrunning::ListOperationsRequest request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::ListOperations");
  internal::OTelScope scope(span);
  auto sr = child_->ListOperations(std::move(request));
  return internal::MakeTracedStreamRange<google::longrunning::Operation>(
      std::move(span), std::move(sr));
}

StatusOr<google::longrunning::Operation>
RuleServiceTracingConnection::GetOperation(
    google::longrunning::GetOperationRequest const& request) {
  auto span =
      internal::MakeSpan("chronicle_v1::RuleServiceConnection::GetOperation");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->GetOperation(request));
}

Status RuleServiceTracingConnection::DeleteOperation(
    google::longrunning::DeleteOperationRequest const& request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::DeleteOperation");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->DeleteOperation(request));
}

Status RuleServiceTracingConnection::CancelOperation(
    google::longrunning::CancelOperationRequest const& request) {
  auto span = internal::MakeSpan(
      "chronicle_v1::RuleServiceConnection::CancelOperation");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->CancelOperation(request));
}

#endif  // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY

std::shared_ptr<chronicle_v1::RuleServiceConnection>
MakeRuleServiceTracingConnection(
    std::shared_ptr<chronicle_v1::RuleServiceConnection> conn) {
#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY
  if (internal::TracingEnabled(conn->options())) {
    conn = std::make_shared<RuleServiceTracingConnection>(std::move(conn));
  }
#endif  // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY
  return conn;
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
}  // namespace chronicle_v1_internal
}  // namespace cloud
}  // namespace google
