// Code generated by sidekick. DO NOT EDIT.
//
// Copyright 2026 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.

import Foundation
#if canImport(FoundationNetworking)
  import FoundationNetworking
#endif
import GoogleCloudWkt
import GoogleLongRunning
import GoogleCloudGax

/// Service for configuring logs-based metrics.
///
/// @Snippet(path: "MetricsServiceV2Quickstart")
public class MetricsServiceV2Client: Clients.MetricsServiceV2Protocol {
  let inner: any Clients.MetricsServiceV2Stub

  /// Creates a new `MetricsServiceV2Client` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.MetricsServiceV2Stub = try Clients.MetricsServiceV2Transport(options)
    inner = Clients.MetricsServiceV2Retry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.MetricsServiceV2Logging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Lists logs-based metrics.
  ///
  /// @Snippet(path: "MetricsServiceV2_ListLogMetrics")
  public func listLogMetrics(
    request: ListLogMetricsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListLogMetricsResponse {
    try await self.inner.listLogMetrics(request: request, options: options)
  }

  /// Lists logs-based metrics.
  ///
  /// @Snippet(path: "MetricsServiceV2_ListLogMetrics")
  public func listLogMetrics(
    byItem: ListLogMetricsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<LogMetric, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudLoggingV2.ListLogMetricsResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listLogMetrics(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Gets a logs-based metric.
  ///
  /// @Snippet(path: "MetricsServiceV2_GetLogMetric")
  public func getLogMetric(
    request: GetLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    try await self.inner.getLogMetric(request: request, options: options)
  }

  /// Creates a logs-based metric.
  ///
  /// @Snippet(path: "MetricsServiceV2_CreateLogMetric")
  public func createLogMetric(
    request: CreateLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    try await self.inner.createLogMetric(request: request, options: options)
  }

  /// Creates or updates a logs-based metric.
  ///
  /// @Snippet(path: "MetricsServiceV2_UpdateLogMetric")
  public func updateLogMetric(
    request: UpdateLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    try await self.inner.updateLogMetric(request: request, options: options)
  }

  /// Deletes a logs-based metric.
  ///
  /// @Snippet(path: "MetricsServiceV2_DeleteLogMetric")
  public func deleteLogMetric(
    request: DeleteLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    try await self.inner.deleteLogMetric(request: request, options: options)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "MetricsServiceV2_ListOperations")
  public func listOperations(
    request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.ListOperationsResponse {
    try await self.inner.listOperations(request: request, options: options)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "MetricsServiceV2_ListOperations")
  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleLongRunning.ListOperationsResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listOperations(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "MetricsServiceV2_GetOperation")
  func getOperation(
    request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.Operation {
    try await self.inner.getOperation(request: request, options: options)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "MetricsServiceV2_CancelOperation")
  public func cancelOperation(
    request: GoogleLongRunning.CancelOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    try await self.inner.cancelOperation(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `MetricsServiceV2Client`.
  ///
  /// To mock `MetricsServiceV2Client` change your functions to receive
  /// `some MetricsServiceV2Protocol` or `any MetricsServiceV2Protocol`
  /// and pass a mock implementation in your tests.
  public protocol MetricsServiceV2Protocol {
    /// See `MetricsServiceV2Client.listLogMetrics`.
    func listLogMetrics(request: ListLogMetricsRequest) async throws
      -> GoogleCloudLoggingV2.ListLogMetricsResponse

    /// See `MetricsServiceV2Client.listLogMetrics`.
    func listLogMetrics(
      byItem: ListLogMetricsRequest
    ) throws -> any AsyncSequence<LogMetric, Swift.Error>

    /// See `MetricsServiceV2Client.listLogMetrics`.
    func listLogMetrics(
      parent: Swift.String,
    ) throws -> any AsyncSequence<LogMetric, Swift.Error>

    /// See `MetricsServiceV2Client.getLogMetric`.
    func getLogMetric(request: GetLogMetricRequest) async throws -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.getLogMetric`.
    func getLogMetric(
      metricName: Swift.String,
    ) async throws -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.createLogMetric`.
    func createLogMetric(request: CreateLogMetricRequest) async throws
      -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.createLogMetric`.
    func createLogMetric(
      parent: Swift.String,
      metric: LogMetric?,
    ) async throws -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.updateLogMetric`.
    func updateLogMetric(request: UpdateLogMetricRequest) async throws
      -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.updateLogMetric`.
    func updateLogMetric(
      metricName: Swift.String,
      metric: LogMetric?,
    ) async throws -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.deleteLogMetric`.
    func deleteLogMetric(request: DeleteLogMetricRequest) async throws

    /// See `MetricsServiceV2Client.deleteLogMetric`.
    func deleteLogMetric(
      metricName: Swift.String,
    ) async throws

    /// See `MetricsServiceV2Client.listOperations`.
    func listOperations(request: GoogleLongRunning.ListOperationsRequest) async throws
      -> GoogleLongRunning.ListOperationsResponse

    /// See `MetricsServiceV2Client.listOperations`.
    func listOperations(
      byItem: GoogleLongRunning.ListOperationsRequest
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>

    /// See `MetricsServiceV2Client.listOperations`.
    func listOperations(
      name: Swift.String,
      filter: Swift.String,
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>

    /// See `MetricsServiceV2Client.cancelOperation`.
    func cancelOperation(request: GoogleLongRunning.CancelOperationRequest) async throws

    /// See `MetricsServiceV2Client.cancelOperation`.
    func cancelOperation(
      name: Swift.String,
    ) async throws

    /// See `MetricsServiceV2Client.listLogMetrics`.
    func listLogMetrics(
      request: ListLogMetricsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.ListLogMetricsResponse

    /// See `MetricsServiceV2Client.listLogMetrics`.
    func listLogMetrics(
      byItem: ListLogMetricsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<LogMetric, Swift.Error>

    /// See `MetricsServiceV2Client.getLogMetric`.
    func getLogMetric(
      request: GetLogMetricRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.createLogMetric`.
    func createLogMetric(
      request: CreateLogMetricRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.updateLogMetric`.
    func updateLogMetric(
      request: UpdateLogMetricRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.LogMetric

    /// See `MetricsServiceV2Client.deleteLogMetric`.
    func deleteLogMetric(
      request: DeleteLogMetricRequest, options: GoogleCloudGax.RequestOptions
    ) async throws

    /// See `MetricsServiceV2Client.listOperations`.
    func listOperations(
      request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.ListOperationsResponse

    /// See `MetricsServiceV2Client.listOperations`.
    func listOperations(
      byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>

    /// See `MetricsServiceV2Client.cancelOperation`.
    func cancelOperation(
      request: GoogleLongRunning.CancelOperationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws
  }
}

// Default implementations
extension Clients.MetricsServiceV2Protocol {
  public func listLogMetrics(request: ListLogMetricsRequest) async throws
    -> GoogleCloudLoggingV2.ListLogMetricsResponse
  {
    try await self.listLogMetrics(request: request, options: .init())
  }

  public func listLogMetrics(
    request: ListLogMetricsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListLogMetricsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listLogMetrics(
    byItem: ListLogMetricsRequest
  ) throws -> any AsyncSequence<LogMetric, Swift.Error> {
    try self.listLogMetrics(byItem: byItem, options: .init())
  }

  public func listLogMetrics(
    byItem: ListLogMetricsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<LogMetric, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudLoggingV2.ListLogMetricsResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listLogMetrics(
    parent: Swift.String,
  ) throws -> any AsyncSequence<LogMetric, Swift.Error> {
    let request = ListLogMetricsRequest().with {
      $0.parent = parent
    }
    return try self.listLogMetrics(byItem: request)
  }

  public func getLogMetric(request: GetLogMetricRequest) async throws
    -> GoogleCloudLoggingV2.LogMetric
  {
    try await self.getLogMetric(request: request, options: .init())
  }

  public func getLogMetric(
    request: GetLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getLogMetric(
    metricName: Swift.String,
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    let request = GetLogMetricRequest().with {
      $0.metricName = metricName
    }
    return try await self.getLogMetric(request: request)
  }

  public func createLogMetric(request: CreateLogMetricRequest) async throws
    -> GoogleCloudLoggingV2.LogMetric
  {
    try await self.createLogMetric(request: request, options: .init())
  }

  public func createLogMetric(
    request: CreateLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func createLogMetric(
    parent: Swift.String,
    metric: LogMetric?,
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    let request = CreateLogMetricRequest().with {
      $0.parent = parent
      $0.metric = metric
    }
    return try await self.createLogMetric(request: request)
  }

  public func updateLogMetric(request: UpdateLogMetricRequest) async throws
    -> GoogleCloudLoggingV2.LogMetric
  {
    try await self.updateLogMetric(request: request, options: .init())
  }

  public func updateLogMetric(
    request: UpdateLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func updateLogMetric(
    metricName: Swift.String,
    metric: LogMetric?,
  ) async throws -> GoogleCloudLoggingV2.LogMetric {
    let request = UpdateLogMetricRequest().with {
      $0.metricName = metricName
      $0.metric = metric
    }
    return try await self.updateLogMetric(request: request)
  }

  public func deleteLogMetric(request: DeleteLogMetricRequest) async throws {
    try await self.deleteLogMetric(request: request, options: .init())
  }

  public func deleteLogMetric(
    request: DeleteLogMetricRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func deleteLogMetric(
    metricName: Swift.String,
  ) async throws {
    let request = DeleteLogMetricRequest().with {
      $0.metricName = metricName
    }
    try await self.deleteLogMetric(request: request)
  }

  public func listOperations(request: GoogleLongRunning.ListOperationsRequest) async throws
    -> GoogleLongRunning.ListOperationsResponse
  {
    try await self.listOperations(request: request, options: .init())
  }

  public func listOperations(
    request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.ListOperationsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    try self.listOperations(byItem: byItem, options: .init())
  }

  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleLongRunning.ListOperationsResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listOperations(
    name: Swift.String,
    filter: Swift.String,
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let request = GoogleLongRunning.ListOperationsRequest().with {
      $0.name = name
      $0.filter = filter
    }
    return try self.listOperations(byItem: request)
  }

  public func getOperation(request: GoogleLongRunning.GetOperationRequest) async throws
    -> GoogleLongRunning.Operation
  {
    try await self.getOperation(request: request, options: .init())
  }

  public func getOperation(
    request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.Operation {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getOperation(
    name: Swift.String,
  ) async throws -> GoogleLongRunning.Operation {
    let request = GoogleLongRunning.GetOperationRequest().with {
      $0.name = name
    }
    return try await self.getOperation(request: request)
  }

  public func cancelOperation(request: GoogleLongRunning.CancelOperationRequest) async throws {
    try await self.cancelOperation(request: request, options: .init())
  }

  public func cancelOperation(
    request: GoogleLongRunning.CancelOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func cancelOperation(
    name: Swift.String,
  ) async throws {
    let request = GoogleLongRunning.CancelOperationRequest().with {
      $0.name = name
    }
    try await self.cancelOperation(request: request)
  }
}
