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

    public init(_ inner: any DatastreamStub, 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 listConnectionProfiles(
      request: ListConnectionProfilesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.ListConnectionProfilesResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListConnectionProfilesRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.ListConnectionProfilesResponse
          in
          return try await self.inner.listConnectionProfiles(request: r, options: o)
        })
    }

    public func getConnectionProfile(
      request: GetConnectionProfileRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.ConnectionProfile {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetConnectionProfileRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.ConnectionProfile
          in
          return try await self.inner.getConnectionProfile(request: r, options: o)
        })
    }

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

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

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

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

    public func listStreams(
      request: ListStreamsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.ListStreamsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListStreamsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.ListStreamsResponse
          in
          return try await self.inner.listStreams(request: r, options: o)
        })
    }

    public func getStream(
      request: GetStreamRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.Stream {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetStreamRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.Stream
          in
          return try await self.inner.getStream(request: r, options: o)
        })
    }

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

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

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

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

    public func getStreamObject(
      request: GetStreamObjectRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.StreamObject {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetStreamObjectRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.StreamObject
          in
          return try await self.inner.getStreamObject(request: r, options: o)
        })
    }

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

    public func listStreamObjects(
      request: ListStreamObjectsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.ListStreamObjectsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListStreamObjectsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.ListStreamObjectsResponse
          in
          return try await self.inner.listStreamObjects(request: r, options: o)
        })
    }

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

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

    public func fetchStaticIps(
      request: FetchStaticIpsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.FetchStaticIpsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: FetchStaticIpsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.FetchStaticIpsResponse
          in
          return try await self.inner.fetchStaticIps(request: r, options: o)
        })
    }

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

    public func getPrivateConnection(
      request: GetPrivateConnectionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.PrivateConnection {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetPrivateConnectionRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.PrivateConnection
          in
          return try await self.inner.getPrivateConnection(request: r, options: o)
        })
    }

    public func listPrivateConnections(
      request: ListPrivateConnectionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.ListPrivateConnectionsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListPrivateConnectionsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.ListPrivateConnectionsResponse
          in
          return try await self.inner.listPrivateConnections(request: r, options: o)
        })
    }

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

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

    public func getRoute(
      request: GetRouteRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.Route {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetRouteRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.Route
          in
          return try await self.inner.getRoute(request: r, options: o)
        })
    }

    public func listRoutes(
      request: ListRoutesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudDatastreamV1.ListRoutesResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListRoutesRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudDatastreamV1.ListRoutesResponse
          in
          return try await self.inner.listRoutes(request: r, options: o)
        })
    }

    public func deleteRoute(
      request: DeleteRouteRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: DeleteRouteRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.deleteRoute(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)
        })
    }
  }
}
