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

extension Clients {
  final class RuleServiceRetry: RuleServiceStub {
    let inner: any RuleServiceStub
    let options: GoogleCloudGax.ClientOptions

    public init(_ inner: any RuleServiceStub, 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 createRule(
      request: CreateRuleRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.Rule {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: false,
        action: {
          (r: CreateRuleRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.Rule
          in
          return try await self.inner.createRule(request: r, options: o)
        })
    }

    public func getRule(
      request: GetRuleRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.Rule {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetRuleRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.Rule
          in
          return try await self.inner.getRule(request: r, options: o)
        })
    }

    public func listRules(
      request: ListRulesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.ListRulesResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListRulesRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.ListRulesResponse
          in
          return try await self.inner.listRules(request: r, options: o)
        })
    }

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

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

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

    public func listRuleRevisions(
      request: ListRuleRevisionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.ListRuleRevisionsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListRuleRevisionsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.ListRuleRevisionsResponse
          in
          return try await self.inner.listRuleRevisions(request: r, options: o)
        })
    }

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

    public func getRetrohunt(
      request: GetRetrohuntRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.Retrohunt {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetRetrohuntRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.Retrohunt
          in
          return try await self.inner.getRetrohunt(request: r, options: o)
        })
    }

    public func listRetrohunts(
      request: ListRetrohuntsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.ListRetrohuntsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListRetrohuntsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.ListRetrohuntsResponse
          in
          return try await self.inner.listRetrohunts(request: r, options: o)
        })
    }

    public func getRuleDeployment(
      request: GetRuleDeploymentRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.RuleDeployment {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: GetRuleDeploymentRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.RuleDeployment
          in
          return try await self.inner.getRuleDeployment(request: r, options: o)
        })
    }

    public func listRuleDeployments(
      request: ListRuleDeploymentsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudChronicleV1.ListRuleDeploymentsResponse {
      try await self._intercept(
        request: request,
        options: options,
        idempotent: true,
        action: {
          (r: ListRuleDeploymentsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudChronicleV1.ListRuleDeploymentsResponse
          in
          return try await self.inner.listRuleDeployments(request: r, options: o)
        })
    }

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