// 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 RegionNotificationEndpoints
  import Foundation
  #if canImport(FoundationNetworking)
    import FoundationNetworking
  #endif
  import GoogleCloudWkt
  import GoogleCloudGax

  /// Service for the `regionNotificationEndpoints` resource.
  ///
  /// @Snippet(path: "regionNotificationEndpointsQuickstart")
  public class RegionNotificationEndpointsClient: Clients.RegionNotificationEndpointsProtocol {
    let inner: any Clients.RegionNotificationEndpointsStub
    let pollingErrorPolicy: GoogleCloudGax.PollingErrorPolicy
    let pollingBackoffPolicy: GoogleCloudGax.BackoffPolicy

    /// Creates a new `RegionNotificationEndpointsClient` instance.
    public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
      var inner: any Clients.RegionNotificationEndpointsStub =
        try Clients.RegionNotificationEndpointsTransport(options)
      inner = Clients.RegionNotificationEndpointsRetry(inner, options: options)
      if let logger = options.logger {
        inner = Clients.RegionNotificationEndpointsLogging(inner, logger: logger)
      }
      self.inner = inner
      self.pollingErrorPolicy = options.pollingErrorPolicy
      self.pollingBackoffPolicy = options.pollingBackoffPolicy
    }

    /// Retrieves the list of all NotificationEndpoint resources,
    /// regional and global, available to the specified project.
    ///
    /// @Snippet(path: "regionNotificationEndpoints_aggregatedList")
    public func aggregatedList(
      request: RegionNotificationEndpointsClient.AggregatedListRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.NotificationEndpointAggregatedList {
      try await self.inner.aggregatedList(request: request, options: options)
    }

    /// Retrieves the list of all NotificationEndpoint resources,
    /// regional and global, available to the specified project.
    ///
    /// @Snippet(path: "regionNotificationEndpoints_aggregatedList")
    public func aggregatedList(
      byItem: RegionNotificationEndpointsClient.AggregatedListRequest,
      options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<(Swift.String, NotificationEndpointsScopedList), Swift.Error> {
      let listRpc = {
        (token: Swift.String) async throws
          -> GoogleCloudComputeV1.NotificationEndpointAggregatedList in
        var request = byItem
        request.pageToken = token
        return try await self.aggregatedList(request: request, options: options)
      }
      return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
    }

    /// Deletes the specified NotificationEndpoint in the given region
    ///
    /// @Snippet(path: "regionNotificationEndpoints_delete")
    public func delete(
      request: RegionNotificationEndpointsClient.DeleteRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.delete(request: request, options: options)
    }

    /// Deletes the specified NotificationEndpoint in the given region
    ///
    /// @Snippet(path: "regionNotificationEndpoints_delete")
    public func delete(
      withPolling: RegionNotificationEndpointsClient.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
            $0.region = withPolling.region
          }, 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 NotificationEndpoint resource in the given region.
    ///
    /// @Snippet(path: "regionNotificationEndpoints_get")
    public func `get`(
      request: RegionNotificationEndpointsClient.GetRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.NotificationEndpoint {
      try await self.inner.`get`(request: request, options: options)
    }

    /// Create a NotificationEndpoint in the specified project in the given region
    /// using the parameters that are included in the request.
    ///
    /// @Snippet(path: "regionNotificationEndpoints_insert")
    public func insert(
      request: RegionNotificationEndpointsClient.InsertRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.insert(request: request, options: options)
    }

    /// Create a NotificationEndpoint in the specified project in the given region
    /// using the parameters that are included in the request.
    ///
    /// @Snippet(path: "regionNotificationEndpoints_insert")
    public func insert(
      withPolling: RegionNotificationEndpointsClient.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
            $0.region = withPolling.region
          }, options: options)
        return try extractStatus(op)
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: initialState,
        polling: options.pollingErrorPolicy ?? self.pollingErrorPolicy,
        backoff: options.pollingBackoffPolicy ?? self.pollingBackoffPolicy,
        poll: poll
      )
    }

    /// Lists the NotificationEndpoints for a project in the given region.
    ///
    /// @Snippet(path: "regionNotificationEndpoints_list")
    public func list(
      request: RegionNotificationEndpointsClient.ListRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.NotificationEndpointList {
      try await self.inner.list(request: request, options: options)
    }

    /// Lists the NotificationEndpoints for a project in the given region.
    ///
    /// @Snippet(path: "regionNotificationEndpoints_list")
    public func list(
      byItem: RegionNotificationEndpointsClient.ListRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<NotificationEndpoint, Swift.Error> {
      let listRpc = {
        (token: Swift.String) async throws -> GoogleCloudComputeV1.NotificationEndpointList 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: "regionNotificationEndpoints_testIamPermissions")
    public func testIamPermissions(
      request: RegionNotificationEndpointsClient.TestIamPermissionsRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.TestPermissionsResponse {
      try await self.inner.testIamPermissions(request: request, options: options)
    }

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

  extension Clients {
    /// A Swift protocol to mock `RegionNotificationEndpointsClient`.
    ///
    /// To mock `RegionNotificationEndpointsClient` change your functions to receive
    /// `some RegionNotificationEndpointsProtocol` or `any RegionNotificationEndpointsProtocol`
    /// and pass a mock implementation in your tests.
    public protocol RegionNotificationEndpointsProtocol {
      /// See `RegionNotificationEndpointsClient.aggregatedList`.
      func aggregatedList(request: RegionNotificationEndpointsClient.AggregatedListRequest)
        async throws -> GoogleCloudComputeV1.NotificationEndpointAggregatedList

      /// See `RegionNotificationEndpointsClient.aggregatedList`.
      func aggregatedList(
        byItem: RegionNotificationEndpointsClient.AggregatedListRequest
      ) throws -> any AsyncSequence<(Swift.String, NotificationEndpointsScopedList), Swift.Error>

      /// See `RegionNotificationEndpointsClient.aggregatedList`.
      func aggregatedList(
        project: Swift.String,
      ) throws -> any AsyncSequence<(Swift.String, NotificationEndpointsScopedList), Swift.Error>

      /// See `RegionNotificationEndpointsClient.delete`.
      func delete(request: RegionNotificationEndpointsClient.DeleteRequest) async throws
        -> GoogleCloudComputeV1.Operation

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

      /// See `RegionNotificationEndpointsClient.`get``.
      func `get`(
        project: Swift.String,
        region: Swift.String,
        notificationEndpoint: Swift.String,
      ) async throws -> GoogleCloudComputeV1.NotificationEndpoint

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

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

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

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

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

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

      /// See `RegionNotificationEndpointsClient.aggregatedList`.
      func aggregatedList(
        request: RegionNotificationEndpointsClient.AggregatedListRequest,
        options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudComputeV1.NotificationEndpointAggregatedList

      /// See `RegionNotificationEndpointsClient.aggregatedList`.
      func aggregatedList(
        byItem: RegionNotificationEndpointsClient.AggregatedListRequest,
        options: GoogleCloudGax.RequestOptions
      ) throws -> any AsyncSequence<(Swift.String, NotificationEndpointsScopedList), Swift.Error>

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

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

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

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

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

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

  // Default implementations
  extension Clients.RegionNotificationEndpointsProtocol {
    public func aggregatedList(request: RegionNotificationEndpointsClient.AggregatedListRequest)
      async throws -> GoogleCloudComputeV1.NotificationEndpointAggregatedList
    {
      try await self.aggregatedList(request: request, options: .init())
    }

    public func aggregatedList(
      request: RegionNotificationEndpointsClient.AggregatedListRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.NotificationEndpointAggregatedList {
      throw GoogleCloudGax.RequestError.unimplemented
    }

    public func aggregatedList(
      byItem: RegionNotificationEndpointsClient.AggregatedListRequest
    ) throws -> any AsyncSequence<(Swift.String, NotificationEndpointsScopedList), Swift.Error> {
      try self.aggregatedList(byItem: byItem, options: .init())
    }

    public func aggregatedList(
      byItem: RegionNotificationEndpointsClient.AggregatedListRequest,
      options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<(Swift.String, NotificationEndpointsScopedList), Swift.Error> {
      let listRpc = {
        (token: Swift.String) async throws
          -> GoogleCloudComputeV1.NotificationEndpointAggregatedList in
        throw GoogleCloudGax.RequestError.unimplemented
      }
      return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
    }

    public func aggregatedList(
      project: Swift.String,
    ) throws -> any AsyncSequence<(Swift.String, NotificationEndpointsScopedList), Swift.Error> {
      let request = RegionNotificationEndpointsClient.AggregatedListRequest().with {
        $0.project = project
      }
      return try self.aggregatedList(byItem: request)
    }

    public func delete(request: RegionNotificationEndpointsClient.DeleteRequest) async throws
      -> GoogleCloudComputeV1.Operation
    {
      try await self.delete(request: request, options: .init())
    }

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

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

    public func delete(
      withPolling: RegionNotificationEndpointsClient.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,
      region: Swift.String,
      notificationEndpoint: Swift.String,
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let request = RegionNotificationEndpointsClient.DeleteRequest().with {
        $0.project = project
        $0.region = region
        $0.notificationEndpoint = notificationEndpoint
      }
      return try await self.delete(withPolling: request)
    }

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

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

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

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

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

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

    public func insert(
      withPolling: RegionNotificationEndpointsClient.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,
      region: Swift.String,
      body: NotificationEndpoint?,
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let request = RegionNotificationEndpointsClient.InsertRequest().with {
        $0.project = project
        $0.region = region
        $0.body = body
      }
      return try await self.insert(withPolling: request)
    }

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

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

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

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

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

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

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

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

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

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