// 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.

#if Routes
  import Foundation
  #if canImport(FoundationNetworking)
    import FoundationNetworking
  #endif
  import GoogleCloudWkt
  import GoogleCloudGax

  /// Service for the `routes` resource.
  ///
  /// @Snippet(path: "routesQuickstart")
  public class RoutesClient: Clients.RoutesProtocol {
    let inner: any Clients.RoutesStub
    let pollingErrorPolicy: GoogleCloudGax.PollingErrorPolicy
    let pollingBackoffPolicy: GoogleCloudGax.BackoffPolicy

    /// Creates a new `RoutesClient` instance.
    public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
      var inner: any Clients.RoutesStub = try Clients.RoutesTransport(options)
      inner = Clients.RoutesRetry(inner, options: options)
      if let logger = options.logger {
        inner = Clients.RoutesLogging(inner, logger: logger)
      }
      self.inner = inner
      self.pollingErrorPolicy = options.pollingErrorPolicy
      self.pollingBackoffPolicy = options.pollingBackoffPolicy
    }

    /// Deletes the specified Route resource.
    ///
    /// @Snippet(path: "routes_delete")
    public func delete(
      request: RoutesClient.DeleteRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.delete(request: request, options: options)
    }

    /// Deletes the specified Route resource.
    ///
    /// @Snippet(path: "routes_delete")
    public func delete(
      withPolling: RoutesClient.DeleteRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let extractStatus = {
        (op: GoogleCloudComputeV1.Operation) throws
          -> GoogleCloudGax._PollableOperationImpl<GoogleCloudComputeV1.Operation>.State in
        guard op._done() else {
          return .init(done: false, result: nil)
        }

        do {
          try op._detectErrors()
        } catch let e as GoogleCloudGax.RequestError {
          return .init(done: true, result: .failure(e))
        }
        return .init(done: true, result: .success(op))
      }
      let rawOp = try await self.delete(request: withPolling, options: options)
      let initialState = try extractStatus(rawOp)
      let poll = {
        () async throws
          -> GoogleCloudGax._PollableOperationImpl<GoogleCloudComputeV1.Operation>.State in
        let op = try await self.getOperation(
          request: .init().with {
            $0.operation = rawOp._name()
            $0.project = withPolling.project
          }, options: options)
        return try extractStatus(op)
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: initialState,
        polling: options.pollingErrorPolicy ?? self.pollingErrorPolicy,
        backoff: options.pollingBackoffPolicy ?? self.pollingBackoffPolicy,
        poll: poll
      )
    }

    /// Returns the specified Route resource.
    ///
    /// @Snippet(path: "routes_get")
    public func `get`(
      request: RoutesClient.GetRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Route {
      try await self.inner.`get`(request: request, options: options)
    }

    /// Creates a Route resource in the specified project using the data included
    /// in the request.
    ///
    /// @Snippet(path: "routes_insert")
    public func insert(
      request: RoutesClient.InsertRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.insert(request: request, options: options)
    }

    /// Creates a Route resource in the specified project using the data included
    /// in the request.
    ///
    /// @Snippet(path: "routes_insert")
    public func insert(
      withPolling: RoutesClient.InsertRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let extractStatus = {
        (op: GoogleCloudComputeV1.Operation) throws
          -> GoogleCloudGax._PollableOperationImpl<GoogleCloudComputeV1.Operation>.State in
        guard op._done() else {
          return .init(done: false, result: nil)
        }

        do {
          try op._detectErrors()
        } catch let e as GoogleCloudGax.RequestError {
          return .init(done: true, result: .failure(e))
        }
        return .init(done: true, result: .success(op))
      }
      let rawOp = try await self.insert(request: withPolling, options: options)
      let initialState = try extractStatus(rawOp)
      let poll = {
        () async throws
          -> GoogleCloudGax._PollableOperationImpl<GoogleCloudComputeV1.Operation>.State in
        let op = try await self.getOperation(
          request: .init().with {
            $0.operation = rawOp._name()
            $0.project = withPolling.project
          }, options: options)
        return try extractStatus(op)
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: initialState,
        polling: options.pollingErrorPolicy ?? self.pollingErrorPolicy,
        backoff: options.pollingBackoffPolicy ?? self.pollingBackoffPolicy,
        poll: poll
      )
    }

    /// Retrieves the list of Route resources available to the specified project.
    ///
    /// @Snippet(path: "routes_list")
    public func list(
      request: RoutesClient.ListRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.RouteList {
      try await self.inner.list(request: request, options: options)
    }

    /// Retrieves the list of Route resources available to the specified project.
    ///
    /// @Snippet(path: "routes_list")
    public func list(
      byItem: RoutesClient.ListRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<Route, Swift.Error> {
      let listRpc = { (token: Swift.String) async throws -> GoogleCloudComputeV1.RouteList in
        var request = byItem
        request.pageToken = token
        return try await self.list(request: request, options: options)
      }
      return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
    }

    /// Returns permissions that a caller has on the specified resource.
    ///
    /// @Snippet(path: "routes_testIamPermissions")
    public func testIamPermissions(
      request: RoutesClient.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.TestPermissionsResponse {
      try await self.inner.testIamPermissions(request: request, options: options)
    }

    /// Retrieves the specified Operations resource.
    ///
    /// @Snippet(path: "routes_getOperation")
    func getOperation(
      request: GlobalOperationsClient.GetRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.getOperation(request: request, options: options)
    }
  }

  extension Clients {
    /// A Swift protocol to mock `RoutesClient`.
    ///
    /// To mock `RoutesClient` change your functions to receive
    /// `some RoutesProtocol` or `any RoutesProtocol`
    /// and pass a mock implementation in your tests.
    public protocol RoutesProtocol {
      /// See `RoutesClient.delete`.
      func delete(request: RoutesClient.DeleteRequest) async throws
        -> GoogleCloudComputeV1.Operation

      /// See `RoutesClient.`get``.
      func `get`(request: RoutesClient.GetRequest) async throws -> GoogleCloudComputeV1.Route

      /// See `RoutesClient.`get``.
      func `get`(
        project: Swift.String,
        route: Swift.String,
      ) async throws -> GoogleCloudComputeV1.Route

      /// See `RoutesClient.insert`.
      func insert(request: RoutesClient.InsertRequest) async throws
        -> GoogleCloudComputeV1.Operation

      /// See `RoutesClient.list`.
      func list(request: RoutesClient.ListRequest) async throws -> GoogleCloudComputeV1.RouteList

      /// See `RoutesClient.list`.
      func list(
        byItem: RoutesClient.ListRequest
      ) throws -> any AsyncSequence<Route, Swift.Error>

      /// See `RoutesClient.list`.
      func list(
        project: Swift.String,
      ) throws -> any AsyncSequence<Route, Swift.Error>

      /// See `RoutesClient.testIamPermissions`.
      func testIamPermissions(request: RoutesClient.TestIamPermissionsRequest) async throws
        -> GoogleCloudComputeV1.TestPermissionsResponse

      /// See `RoutesClient.testIamPermissions`.
      func testIamPermissions(
        project: Swift.String,
        resource: Swift.String,
        body: TestPermissionsRequest?,
      ) async throws -> GoogleCloudComputeV1.TestPermissionsResponse

      /// See `RoutesClient.delete`.
      func delete(
        request: RoutesClient.DeleteRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudComputeV1.Operation

      /// See `RoutesClient.`get``.
      func `get`(
        request: RoutesClient.GetRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudComputeV1.Route

      /// See `RoutesClient.insert`.
      func insert(
        request: RoutesClient.InsertRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudComputeV1.Operation

      /// See `RoutesClient.list`.
      func list(
        request: RoutesClient.ListRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudComputeV1.RouteList

      /// See `RoutesClient.list`.
      func list(
        byItem: RoutesClient.ListRequest, options: GoogleCloudGax.RequestOptions
      ) throws -> any AsyncSequence<Route, Swift.Error>

      /// See `RoutesClient.testIamPermissions`.
      func testIamPermissions(
        request: RoutesClient.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudComputeV1.TestPermissionsResponse
    }
  }

  // Default implementations
  extension Clients.RoutesProtocol {
    public func delete(request: RoutesClient.DeleteRequest) async throws
      -> GoogleCloudComputeV1.Operation
    {
      try await self.delete(request: request, options: .init())
    }

    public func delete(
      request: RoutesClient.DeleteRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      throw GoogleCloudGax.RequestError.unimplemented
    }

    public func delete(
      withPolling: RoutesClient.DeleteRequest
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      try await self.delete(withPolling: withPolling, options: .init())
    }

    public func delete(
      withPolling: RoutesClient.DeleteRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let poll = {
        () async throws
          -> GoogleCloudGax._PollableOperationImpl<GoogleCloudComputeV1.Operation>.State in
        throw GoogleCloudGax.RequestError.unimplemented
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: .init(done: false, result: nil), poll: poll)
    }

    public func delete(
      project: Swift.String,
      route: Swift.String,
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let request = RoutesClient.DeleteRequest().with {
        $0.project = project
        $0.route = route
      }
      return try await self.delete(withPolling: request)
    }

    public func `get`(request: RoutesClient.GetRequest) async throws -> GoogleCloudComputeV1.Route {
      try await self.`get`(request: request, options: .init())
    }

    public func `get`(
      request: RoutesClient.GetRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Route {
      throw GoogleCloudGax.RequestError.unimplemented
    }

    public func `get`(
      project: Swift.String,
      route: Swift.String,
    ) async throws -> GoogleCloudComputeV1.Route {
      let request = RoutesClient.GetRequest().with {
        $0.project = project
        $0.route = route
      }
      return try await self.`get`(request: request)
    }

    public func insert(request: RoutesClient.InsertRequest) async throws
      -> GoogleCloudComputeV1.Operation
    {
      try await self.insert(request: request, options: .init())
    }

    public func insert(
      request: RoutesClient.InsertRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      throw GoogleCloudGax.RequestError.unimplemented
    }

    public func insert(
      withPolling: RoutesClient.InsertRequest
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      try await self.insert(withPolling: withPolling, options: .init())
    }

    public func insert(
      withPolling: RoutesClient.InsertRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let poll = {
        () async throws
          -> GoogleCloudGax._PollableOperationImpl<GoogleCloudComputeV1.Operation>.State in
        throw GoogleCloudGax.RequestError.unimplemented
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: .init(done: false, result: nil), poll: poll)
    }

    public func insert(
      project: Swift.String,
      body: Route?,
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let request = RoutesClient.InsertRequest().with {
        $0.project = project
        $0.body = body
      }
      return try await self.insert(withPolling: request)
    }

    public func list(request: RoutesClient.ListRequest) async throws
      -> GoogleCloudComputeV1.RouteList
    {
      try await self.list(request: request, options: .init())
    }

    public func list(
      request: RoutesClient.ListRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.RouteList {
      throw GoogleCloudGax.RequestError.unimplemented
    }

    public func list(
      byItem: RoutesClient.ListRequest
    ) throws -> any AsyncSequence<Route, Swift.Error> {
      try self.list(byItem: byItem, options: .init())
    }

    public func list(
      byItem: RoutesClient.ListRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<Route, Swift.Error> {
      let listRpc = { (token: Swift.String) async throws -> GoogleCloudComputeV1.RouteList in
        throw GoogleCloudGax.RequestError.unimplemented
      }
      return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
    }

    public func list(
      project: Swift.String,
    ) throws -> any AsyncSequence<Route, Swift.Error> {
      let request = RoutesClient.ListRequest().with {
        $0.project = project
      }
      return try self.list(byItem: request)
    }

    public func testIamPermissions(request: RoutesClient.TestIamPermissionsRequest) async throws
      -> GoogleCloudComputeV1.TestPermissionsResponse
    {
      try await self.testIamPermissions(request: request, options: .init())
    }

    public func testIamPermissions(
      request: RoutesClient.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.TestPermissionsResponse {
      throw GoogleCloudGax.RequestError.unimplemented
    }

    public func testIamPermissions(
      project: Swift.String,
      resource: Swift.String,
      body: TestPermissionsRequest?,
    ) async throws -> GoogleCloudComputeV1.TestPermissionsResponse {
      let request = RoutesClient.TestIamPermissionsRequest().with {
        $0.project = project
        $0.resource = resource
        $0.body = body
      }
      return try await self.testIamPermissions(request: request)
    }

    public func getOperation(request: GlobalOperationsClient.GetRequest) async throws
      -> GoogleCloudComputeV1.Operation
    {
      try await self.getOperation(request: request, options: .init())
    }

    public func getOperation(
      request: GlobalOperationsClient.GetRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      throw GoogleCloudGax.RequestError.unimplemented
    }
  }
#endif
