// 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 GoogleCloudLocation
import GoogleCloudWkt
import GoogleLongRunning
import GoogleRpc
import GoogleCloudGax

extension Clients {
  final class LicenseManagerRetry: LicenseManagerStub {
    let inner: any LicenseManagerStub
    let options: GoogleCloudGax.ClientOptions

    public init(_ inner: any LicenseManagerStub, options: GoogleCloudGax.ClientOptions) {
      self.inner = inner
      self.options = options
    }

    func _intercept<Input, Output>(
      request: Input,
      options: GoogleCloudGax.RequestOptions,
      idempotent: Swift.Bool,
      action: (Input, GoogleCloudGax.RequestOptions) async throws -> Output,
    ) async throws -> Output {
      let loop = GoogleCloudGax._RetryLoop(
        options: options, withDefault: self.options, idempotent: idempotent,
      )
      let attempt = { (attemptTimeout: Swift.Duration?) async throws -> Output in
        var attemptOptions = options
        attemptOptions.attemptTimeout = attemptTimeout
        return try await action(request, attemptOptions)
      }
      return try await loop.run(attempt: attempt)
    }

    public func listConfigurations(
      request: ListConfigurationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.ListConfigurationsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListConfigurationsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.ListConfigurationsResponse
          in
          return try await self.inner.listConfigurations(request: r, options: o)
        })
    }

    public func getConfiguration(
      request: GetConfigurationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.Configuration {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetConfigurationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.Configuration
          in
          return try await self.inner.getConfiguration(request: r, options: o)
        })
    }

    public func createConfiguration(
      request: CreateConfigurationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: CreateConfigurationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.createConfiguration(request: r, options: o)
        })
    }

    public func updateConfiguration(
      request: UpdateConfigurationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: UpdateConfigurationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.updateConfiguration(request: r, options: o)
        })
    }

    public func deleteConfiguration(
      request: DeleteConfigurationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: DeleteConfigurationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.deleteConfiguration(request: r, options: o)
        })
    }

    public func listInstances(
      request: ListInstancesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.ListInstancesResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListInstancesRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.ListInstancesResponse
          in
          return try await self.inner.listInstances(request: r, options: o)
        })
    }

    public func getInstance(
      request: GetInstanceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.Instance {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetInstanceRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.Instance
          in
          return try await self.inner.getInstance(request: r, options: o)
        })
    }

    public func deactivateConfiguration(
      request: DeactivateConfigurationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: DeactivateConfigurationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.deactivateConfiguration(request: r, options: o)
        })
    }

    public func reactivateConfiguration(
      request: ReactivateConfigurationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: ReactivateConfigurationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.reactivateConfiguration(request: r, options: o)
        })
    }

    public func queryConfigurationLicenseUsage(
      request: QueryConfigurationLicenseUsageRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.QueryConfigurationLicenseUsageResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: QueryConfigurationLicenseUsageRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.QueryConfigurationLicenseUsageResponse
          in
          return try await self.inner.queryConfigurationLicenseUsage(request: r, options: o)
        })
    }

    public func aggregateUsage(
      request: AggregateUsageRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.AggregateUsageResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: AggregateUsageRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.AggregateUsageResponse
          in
          return try await self.inner.aggregateUsage(request: r, options: o)
        })
    }

    public func listProducts(
      request: ListProductsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.ListProductsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListProductsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.ListProductsResponse
          in
          return try await self.inner.listProducts(request: r, options: o)
        })
    }

    public func getProduct(
      request: GetProductRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLicenseManagerV1.Product {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetProductRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLicenseManagerV1.Product
          in
          return try await self.inner.getProduct(request: r, options: o)
        })
    }

    public func listLocations(
      request: GoogleCloudLocation.ListLocationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLocation.ListLocationsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GoogleCloudLocation.ListLocationsRequest, o: GoogleCloudGax.RequestOptions)
            async throws -> GoogleCloudLocation.ListLocationsResponse
          in
          return try await self.inner.listLocations(request: r, options: o)
        })
    }

    public func getLocation(
      request: GoogleCloudLocation.GetLocationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLocation.Location {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GoogleCloudLocation.GetLocationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudLocation.Location
          in
          return try await self.inner.getLocation(request: r, options: o)
        })
    }

    public func listOperations(
      request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.ListOperationsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GoogleLongRunning.ListOperationsRequest, o: GoogleCloudGax.RequestOptions)
            async throws -> GoogleLongRunning.ListOperationsResponse
          in
          return try await self.inner.listOperations(request: r, options: o)
        })
    }

    public func getOperation(
      request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GoogleLongRunning.GetOperationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.getOperation(request: r, options: o)
        })
    }

    public func deleteOperation(
      request: GoogleLongRunning.DeleteOperationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: GoogleLongRunning.DeleteOperationRequest, o: GoogleCloudGax.RequestOptions)
            async throws -> Void in
          return try await self.inner.deleteOperation(request: r, options: o)
        })
    }

    public func cancelOperation(
      request: GoogleLongRunning.CancelOperationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: GoogleLongRunning.CancelOperationRequest, o: GoogleCloudGax.RequestOptions)
            async throws -> Void in
          return try await self.inner.cancelOperation(request: r, options: o)
        })
    }
  }
}
