// Copyright 2024 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/kms/v1/autokey.proto

#include "google/cloud/kms/v1/internal/autokey_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 kms_v1_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

AutokeyTracingConnection::AutokeyTracingConnection(
    std::shared_ptr<kms_v1::AutokeyConnection> child)
    : child_(std::move(child)) {}

future<StatusOr<google::cloud::kms::v1::KeyHandle>>
AutokeyTracingConnection::CreateKeyHandle(
    google::cloud::kms::v1::CreateKeyHandleRequest const& request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::CreateKeyHandle");
  internal::OTelScope scope(span);
  return internal::EndSpan(std::move(span), child_->CreateKeyHandle(request));
}

StatusOr<google::longrunning::Operation>
AutokeyTracingConnection::CreateKeyHandle(
    NoAwaitTag, google::cloud::kms::v1::CreateKeyHandleRequest const& request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::CreateKeyHandle");
  opentelemetry::trace::Scope scope(span);
  return internal::EndSpan(*span,
                           child_->CreateKeyHandle(NoAwaitTag{}, request));
}

future<StatusOr<google::cloud::kms::v1::KeyHandle>>
AutokeyTracingConnection::CreateKeyHandle(
    google::longrunning::Operation const& operation) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::CreateKeyHandle");
  internal::OTelScope scope(span);
  return internal::EndSpan(std::move(span), child_->CreateKeyHandle(operation));
}

StatusOr<google::cloud::kms::v1::KeyHandle>
AutokeyTracingConnection::GetKeyHandle(
    google::cloud::kms::v1::GetKeyHandleRequest const& request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::GetKeyHandle");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->GetKeyHandle(request));
}

StreamRange<google::cloud::kms::v1::KeyHandle>
AutokeyTracingConnection::ListKeyHandles(
    google::cloud::kms::v1::ListKeyHandlesRequest request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::ListKeyHandles");
  internal::OTelScope scope(span);
  auto sr = child_->ListKeyHandles(std::move(request));
  return internal::MakeTracedStreamRange<google::cloud::kms::v1::KeyHandle>(
      std::move(span), std::move(sr));
}

StreamRange<google::cloud::location::Location>
AutokeyTracingConnection::ListLocations(
    google::cloud::location::ListLocationsRequest request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::ListLocations");
  internal::OTelScope scope(span);
  auto sr = child_->ListLocations(std::move(request));
  return internal::MakeTracedStreamRange<google::cloud::location::Location>(
      std::move(span), std::move(sr));
}

StatusOr<google::cloud::location::Location>
AutokeyTracingConnection::GetLocation(
    google::cloud::location::GetLocationRequest const& request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::GetLocation");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->GetLocation(request));
}

StatusOr<google::iam::v1::Policy> AutokeyTracingConnection::SetIamPolicy(
    google::iam::v1::SetIamPolicyRequest const& request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::SetIamPolicy");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->SetIamPolicy(request));
}

StatusOr<google::iam::v1::Policy> AutokeyTracingConnection::GetIamPolicy(
    google::iam::v1::GetIamPolicyRequest const& request) {
  auto span = internal::MakeSpan("kms_v1::AutokeyConnection::GetIamPolicy");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->GetIamPolicy(request));
}

StatusOr<google::iam::v1::TestIamPermissionsResponse>
AutokeyTracingConnection::TestIamPermissions(
    google::iam::v1::TestIamPermissionsRequest const& request) {
  auto span =
      internal::MakeSpan("kms_v1::AutokeyConnection::TestIamPermissions");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->TestIamPermissions(request));
}

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

std::shared_ptr<kms_v1::AutokeyConnection> MakeAutokeyTracingConnection(
    std::shared_ptr<kms_v1::AutokeyConnection> conn) {
  if (internal::TracingEnabled(conn->options())) {
    conn = std::make_shared<AutokeyTracingConnection>(std::move(conn));
  }
  return conn;
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
}  // namespace kms_v1_internal
}  // namespace cloud
}  // namespace google
