// 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 GoogleCloudGax

/// The QueryService API is used to manage time series data in Cloud
/// Monitoring. Time series data is a collection of data points that describes
/// the time-varying values of a metric.
///
/// @Snippet(path: "QueryServiceQuickstart")
public class QueryServiceClient: Clients.QueryServiceProtocol {
  let inner: any Clients.QueryServiceStub

  /// Creates a new `QueryServiceClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.QueryServiceStub = try Clients.QueryServiceTransport(options)
    inner = Clients.QueryServiceRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.QueryServiceLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Queries time series by using Monitoring Query Language (MQL). We recommend
  /// using PromQL instead of MQL. For more information about the status of MQL,
  /// see the [MQL deprecation
  /// notice](https://cloud.google.com/stackdriver/docs/deprecations/mql).
  ///
  /// @Snippet(path: "QueryService_QueryTimeSeries")
  @available(*, deprecated)
  public func queryTimeSeries(
    request: QueryTimeSeriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudMonitoringV3.QueryTimeSeriesResponse {
    try await self.inner.queryTimeSeries(request: request, options: options)
  }

  /// Queries time series by using Monitoring Query Language (MQL). We recommend
  /// using PromQL instead of MQL. For more information about the status of MQL,
  /// see the [MQL deprecation
  /// notice](https://cloud.google.com/stackdriver/docs/deprecations/mql).
  ///
  /// @Snippet(path: "QueryService_QueryTimeSeries")
  @available(*, deprecated)
  public func queryTimeSeries(
    byItem: QueryTimeSeriesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<TimeSeriesData, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudMonitoringV3.QueryTimeSeriesResponse in
      var request = byItem
      request.pageToken = token
      return try await self.queryTimeSeries(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }
}

extension Clients {
  /// A Swift protocol to mock `QueryServiceClient`.
  ///
  /// To mock `QueryServiceClient` change your functions to receive
  /// `some QueryServiceProtocol` or `any QueryServiceProtocol`
  /// and pass a mock implementation in your tests.
  public protocol QueryServiceProtocol {
    /// See `QueryServiceClient.queryTimeSeries`.
    @available(*, deprecated)
    func queryTimeSeries(request: QueryTimeSeriesRequest) async throws
      -> GoogleCloudMonitoringV3.QueryTimeSeriesResponse

    /// See `QueryServiceClient.queryTimeSeries`.
    @available(*, deprecated)
    func queryTimeSeries(
      byItem: QueryTimeSeriesRequest
    ) throws -> any AsyncSequence<TimeSeriesData, Swift.Error>

    /// See `QueryServiceClient.queryTimeSeries`.
    @available(*, deprecated)
    func queryTimeSeries(
      request: QueryTimeSeriesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudMonitoringV3.QueryTimeSeriesResponse

    /// See `QueryServiceClient.queryTimeSeries`.
    @available(*, deprecated)
    func queryTimeSeries(
      byItem: QueryTimeSeriesRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<TimeSeriesData, Swift.Error>
  }
}

// Default implementations
extension Clients.QueryServiceProtocol {
  public func queryTimeSeries(request: QueryTimeSeriesRequest) async throws
    -> GoogleCloudMonitoringV3.QueryTimeSeriesResponse
  {
    try await self.queryTimeSeries(request: request, options: .init())
  }

  public func queryTimeSeries(
    request: QueryTimeSeriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudMonitoringV3.QueryTimeSeriesResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func queryTimeSeries(
    byItem: QueryTimeSeriesRequest
  ) throws -> any AsyncSequence<TimeSeriesData, Swift.Error> {
    try self.queryTimeSeries(byItem: byItem, options: .init())
  }

  public func queryTimeSeries(
    byItem: QueryTimeSeriesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<TimeSeriesData, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudMonitoringV3.QueryTimeSeriesResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }
}
