// Copyright 2023 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/aiplatform/v1/prediction_service.proto

#include "google/cloud/aiplatform/v1/internal/prediction_tracing_connection.h"
#include "google/cloud/internal/opentelemetry.h"
#include "google/cloud/internal/traced_stream_range.h"
#include <memory>

namespace google {
namespace cloud {
namespace aiplatform_v1_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY

PredictionServiceTracingConnection::PredictionServiceTracingConnection(
    std::shared_ptr<aiplatform_v1::PredictionServiceConnection> child)
    : child_(std::move(child)) {}

StatusOr<google::cloud::aiplatform::v1::PredictResponse>
PredictionServiceTracingConnection::Predict(
    google::cloud::aiplatform::v1::PredictRequest const& request) {
  auto span =
      internal::MakeSpan("aiplatform_v1::PredictionServiceConnection::Predict");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->Predict(request));
}

StatusOr<google::api::HttpBody> PredictionServiceTracingConnection::RawPredict(
    google::cloud::aiplatform::v1::RawPredictRequest const& request) {
  auto span = internal::MakeSpan(
      "aiplatform_v1::PredictionServiceConnection::RawPredict");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->RawPredict(request));
}

StatusOr<google::cloud::aiplatform::v1::DirectPredictResponse>
PredictionServiceTracingConnection::DirectPredict(
    google::cloud::aiplatform::v1::DirectPredictRequest const& request) {
  auto span = internal::MakeSpan(
      "aiplatform_v1::PredictionServiceConnection::DirectPredict");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->DirectPredict(request));
}

StatusOr<google::cloud::aiplatform::v1::DirectRawPredictResponse>
PredictionServiceTracingConnection::DirectRawPredict(
    google::cloud::aiplatform::v1::DirectRawPredictRequest const& request) {
  auto span = internal::MakeSpan(
      "aiplatform_v1::PredictionServiceConnection::DirectRawPredict");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->DirectRawPredict(request));
}

std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
    google::cloud::aiplatform::v1::StreamingPredictRequest,
    google::cloud::aiplatform::v1::StreamingPredictResponse>>
PredictionServiceTracingConnection::AsyncStreamingPredict() {
  return child_->AsyncStreamingPredict();
}

StreamRange<google::cloud::aiplatform::v1::StreamingPredictResponse>
PredictionServiceTracingConnection::ServerStreamingPredict(
    google::cloud::aiplatform::v1::StreamingPredictRequest const& request) {
  auto span = internal::MakeSpan(
      "aiplatform_v1::PredictionServiceConnection::ServerStreamingPredict");
  internal::OTelScope scope(span);
  auto sr = child_->ServerStreamingPredict(request);
  return internal::MakeTracedStreamRange<
      google::cloud::aiplatform::v1::StreamingPredictResponse>(std::move(span),
                                                               std::move(sr));
}
std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
    google::cloud::aiplatform::v1::StreamingRawPredictRequest,
    google::cloud::aiplatform::v1::StreamingRawPredictResponse>>
PredictionServiceTracingConnection::AsyncStreamingRawPredict() {
  return child_->AsyncStreamingRawPredict();
}

StatusOr<google::cloud::aiplatform::v1::ExplainResponse>
PredictionServiceTracingConnection::Explain(
    google::cloud::aiplatform::v1::ExplainRequest const& request) {
  auto span =
      internal::MakeSpan("aiplatform_v1::PredictionServiceConnection::Explain");
  auto scope = opentelemetry::trace::Scope(span);
  return internal::EndSpan(*span, child_->Explain(request));
}

#endif  // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY

std::shared_ptr<aiplatform_v1::PredictionServiceConnection>
MakePredictionServiceTracingConnection(
    std::shared_ptr<aiplatform_v1::PredictionServiceConnection> conn) {
#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY
  if (internal::TracingEnabled(conn->options())) {
    conn =
        std::make_shared<PredictionServiceTracingConnection>(std::move(conn));
  }
#endif  // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY
  return conn;
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
}  // namespace aiplatform_v1_internal
}  // namespace cloud
}  // namespace google
