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

extension Clients {
  final class ServiceManagerRetry: ServiceManagerStub {
    let inner: any ServiceManagerStub
    let options: GoogleCloudGax.ClientOptions

    public init(_ inner: any ServiceManagerStub, 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 listServices(
      request: ListServicesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiServiceManagementV1.ListServicesResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListServicesRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiServiceManagementV1.ListServicesResponse
          in
          return try await self.inner.listServices(request: r, options: o)
        })
    }

    public func getService(
      request: GetServiceRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiServiceManagementV1.ManagedService {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetServiceRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiServiceManagementV1.ManagedService
          in
          return try await self.inner.getService(request: r, options: o)
        })
    }

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

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

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

    public func listServiceConfigs(
      request: ListServiceConfigsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiServiceManagementV1.ListServiceConfigsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListServiceConfigsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiServiceManagementV1.ListServiceConfigsResponse
          in
          return try await self.inner.listServiceConfigs(request: r, options: o)
        })
    }

    public func getServiceConfig(
      request: GetServiceConfigRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApi.Service {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetServiceConfigRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApi.Service
          in
          return try await self.inner.getServiceConfig(request: r, options: o)
        })
    }

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

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

    public func listServiceRollouts(
      request: ListServiceRolloutsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiServiceManagementV1.ListServiceRolloutsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListServiceRolloutsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiServiceManagementV1.ListServiceRolloutsResponse
          in
          return try await self.inner.listServiceRollouts(request: r, options: o)
        })
    }

    public func getServiceRollout(
      request: GetServiceRolloutRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiServiceManagementV1.Rollout {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetServiceRolloutRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiServiceManagementV1.Rollout
          in
          return try await self.inner.getServiceRollout(request: r, options: o)
        })
    }

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

    public func generateConfigReport(
      request: GenerateConfigReportRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiServiceManagementV1.GenerateConfigReportResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: GenerateConfigReportRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiServiceManagementV1.GenerateConfigReportResponse
          in
          return try await self.inner.generateConfigReport(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 getIamPolicy(
      request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.Policy {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: GoogleIAMV1.GetIamPolicyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleIAMV1.Policy
          in
          return try await self.inner.getIamPolicy(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 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)
        })
    }
  }
}
