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

extension Clients {
  final class ReservationServiceRetry: ReservationServiceStub {
    let inner: any ReservationServiceStub
    let options: GoogleCloudGax.ClientOptions

    public init(_ inner: any ReservationServiceStub, 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 createReservation(
      request: CreateReservationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.Reservation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: CreateReservationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.Reservation
          in
          return try await self.inner.createReservation(request: r, options: o)
        })
    }

    public func listReservations(
      request: ListReservationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.ListReservationsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListReservationsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.ListReservationsResponse
          in
          return try await self.inner.listReservations(request: r, options: o)
        })
    }

    public func getReservation(
      request: GetReservationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.Reservation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetReservationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.Reservation
          in
          return try await self.inner.getReservation(request: r, options: o)
        })
    }

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

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

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

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

    public func listCapacityCommitments(
      request: ListCapacityCommitmentsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.ListCapacityCommitmentsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListCapacityCommitmentsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.ListCapacityCommitmentsResponse
          in
          return try await self.inner.listCapacityCommitments(request: r, options: o)
        })
    }

    public func getCapacityCommitment(
      request: GetCapacityCommitmentRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.CapacityCommitment {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetCapacityCommitmentRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.CapacityCommitment
          in
          return try await self.inner.getCapacityCommitment(request: r, options: o)
        })
    }

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

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

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

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

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

    public func listAssignments(
      request: ListAssignmentsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.ListAssignmentsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListAssignmentsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.ListAssignmentsResponse
          in
          return try await self.inner.listAssignments(request: r, options: o)
        })
    }

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

    public func searchAssignments(
      request: SearchAssignmentsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.SearchAssignmentsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: SearchAssignmentsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.SearchAssignmentsResponse
          in
          return try await self.inner.searchAssignments(request: r, options: o)
        })
    }

    public func searchAllAssignments(
      request: SearchAllAssignmentsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.SearchAllAssignmentsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: SearchAllAssignmentsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.SearchAllAssignmentsResponse
          in
          return try await self.inner.searchAllAssignments(request: r, options: o)
        })
    }

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

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

    public func getBiReservation(
      request: GetBiReservationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.BiReservation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetBiReservationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.BiReservation
          in
          return try await self.inner.getBiReservation(request: r, options: o)
        })
    }

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

    public func getIamPolicy(
      request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.Policy {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GoogleIAMV1.GetIamPolicyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleIAMV1.Policy
          in
          return try await self.inner.getIamPolicy(request: r, options: o)
        })
    }

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

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

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

    public func getReservationGroup(
      request: GetReservationGroupRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.ReservationGroup {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetReservationGroupRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.ReservationGroup
          in
          return try await self.inner.getReservationGroup(request: r, options: o)
        })
    }

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

    public func listReservationGroups(
      request: ListReservationGroupsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryReservationV1.ListReservationGroupsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListReservationGroupsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleBigQueryReservationV1.ListReservationGroupsResponse
          in
          return try await self.inner.listReservationGroups(request: r, options: o)
        })
    }
  }
}
