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

/// [Google Quota Control API](https://cloud.google.com/service-control/overview)
///
/// Allows clients to allocate and release quota against a [managed
/// service](https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).
///
/// @Snippet(path: "QuotaControllerQuickstart")
public class QuotaControllerClient: Clients.QuotaControllerProtocol {
  let inner: any Clients.QuotaControllerStub

  /// Creates a new `QuotaControllerClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.QuotaControllerStub = try Clients.QuotaControllerTransport(options)
    inner = Clients.QuotaControllerRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.QuotaControllerLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Attempts to allocate quota for the specified consumer. It should be called
  /// before the operation is executed.
  ///
  /// This method requires the `servicemanagement.services.quota`
  /// permission on the specified service. For more information, see
  /// [Cloud IAM](https://cloud.google.com/iam).
  ///
  /// **NOTE:** The client **must** fail-open on server errors `INTERNAL`,
  /// `UNKNOWN`, `DEADLINE_EXCEEDED`, and `UNAVAILABLE`. To ensure system
  /// reliability, the server may inject these errors to prohibit any hard
  /// dependency on the quota functionality.
  ///
  /// @Snippet(path: "QuotaController_AllocateQuota")
  public func allocateQuota(
    request: AllocateQuotaRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleApiServiceControlV1.AllocateQuotaResponse {
    try await self.inner.allocateQuota(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `QuotaControllerClient`.
  ///
  /// To mock `QuotaControllerClient` change your functions to receive
  /// `some QuotaControllerProtocol` or `any QuotaControllerProtocol`
  /// and pass a mock implementation in your tests.
  public protocol QuotaControllerProtocol {
    /// See `QuotaControllerClient.allocateQuota`.
    func allocateQuota(request: AllocateQuotaRequest) async throws
      -> GoogleApiServiceControlV1.AllocateQuotaResponse

    /// See `QuotaControllerClient.allocateQuota`.
    func allocateQuota(
      request: AllocateQuotaRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiServiceControlV1.AllocateQuotaResponse
  }
}

// Default implementations
extension Clients.QuotaControllerProtocol {
  public func allocateQuota(request: AllocateQuotaRequest) async throws
    -> GoogleApiServiceControlV1.AllocateQuotaResponse
  {
    try await self.allocateQuota(request: request, options: .init())
  }

  public func allocateQuota(
    request: AllocateQuotaRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleApiServiceControlV1.AllocateQuotaResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }
}
