// 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 AlloyDBAdminRetry: AlloyDBAdminStub {
    let inner: any AlloyDBAdminStub
    let options: GoogleCloudGax.ClientOptions

    public init(_ inner: any AlloyDBAdminStub, 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 listClusters(
      request: ListClustersRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.ListClustersResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListClustersRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.ListClustersResponse
          in
          return try await self.inner.listClusters(request: r, options: o)
        })
    }

    public func getCluster(
      request: GetClusterRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.Cluster {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetClusterRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.Cluster
          in
          return try await self.inner.getCluster(request: r, options: o)
        })
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    public func executeSql(
      request: ExecuteSqlRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.ExecuteSqlResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: ExecuteSqlRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.ExecuteSqlResponse
          in
          return try await self.inner.executeSql(request: r, options: o)
        })
    }

    public func listBackups(
      request: ListBackupsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.ListBackupsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListBackupsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.ListBackupsResponse
          in
          return try await self.inner.listBackups(request: r, options: o)
        })
    }

    public func getBackup(
      request: GetBackupRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.Backup {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetBackupRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.Backup
          in
          return try await self.inner.getBackup(request: r, options: o)
        })
    }

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

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

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

    public func listSupportedDatabaseFlags(
      request: ListSupportedDatabaseFlagsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.ListSupportedDatabaseFlagsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListSupportedDatabaseFlagsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.ListSupportedDatabaseFlagsResponse
          in
          return try await self.inner.listSupportedDatabaseFlags(request: r, options: o)
        })
    }

    public func generateClientCertificate(
      request: GenerateClientCertificateRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.GenerateClientCertificateResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: GenerateClientCertificateRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.GenerateClientCertificateResponse
          in
          return try await self.inner.generateClientCertificate(request: r, options: o)
        })
    }

    public func getConnectionInfo(
      request: GetConnectionInfoRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.ConnectionInfo {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetConnectionInfoRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.ConnectionInfo
          in
          return try await self.inner.getConnectionInfo(request: r, options: o)
        })
    }

    public func listUsers(
      request: ListUsersRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.ListUsersResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListUsersRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.ListUsersResponse
          in
          return try await self.inner.listUsers(request: r, options: o)
        })
    }

    public func getUser(
      request: GetUserRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.User {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetUserRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.User
          in
          return try await self.inner.getUser(request: r, options: o)
        })
    }

    public func createUser(
      request: CreateUserRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.User {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: CreateUserRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.User
          in
          return try await self.inner.createUser(request: r, options: o)
        })
    }

    public func updateUser(
      request: UpdateUserRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.User {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: UpdateUserRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.User
          in
          return try await self.inner.updateUser(request: r, options: o)
        })
    }

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

    public func listDatabases(
      request: ListDatabasesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudAlloyDBV1.ListDatabasesResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListDatabasesRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudAlloyDBV1.ListDatabasesResponse
          in
          return try await self.inner.listDatabases(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)
        })
    }
  }
}
