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

  /// Service for the `instanceGroupManagerResizeRequests` resource.
  ///
  /// @Snippet(path: "instanceGroupManagerResizeRequestsQuickstart")
  public class InstanceGroupManagerResizeRequestsClient: Clients
      .InstanceGroupManagerResizeRequestsProtocol
  {
    let inner: any Clients.InstanceGroupManagerResizeRequestsStub
    let pollingErrorPolicy: GoogleCloudGax.PollingErrorPolicy
    let pollingBackoffPolicy: GoogleCloudGax.BackoffPolicy

    /// Creates a new `InstanceGroupManagerResizeRequestsClient` instance.
    public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
      var inner: any Clients.InstanceGroupManagerResizeRequestsStub =
        try Clients.InstanceGroupManagerResizeRequestsTransport(options)
      inner = Clients.InstanceGroupManagerResizeRequestsRetry(inner, options: options)
      if let logger = options.logger {
        inner = Clients.InstanceGroupManagerResizeRequestsLogging(inner, logger: logger)
      }
      self.inner = inner
      self.pollingErrorPolicy = options.pollingErrorPolicy
      self.pollingBackoffPolicy = options.pollingBackoffPolicy
    }

    /// Cancels the specified resize request and removes it from the queue.
    /// Cancelled resize request does no longer wait for the resources to be
    /// provisioned. Cancel is only possible for requests that are accepted in the
    /// queue.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_cancel")
    public func cancel(
      request: InstanceGroupManagerResizeRequestsClient.CancelRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.cancel(request: request, options: options)
    }

    /// Cancels the specified resize request and removes it from the queue.
    /// Cancelled resize request does no longer wait for the resources to be
    /// provisioned. Cancel is only possible for requests that are accepted in the
    /// queue.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_cancel")
    public func cancel(
      withPolling: InstanceGroupManagerResizeRequestsClient.CancelRequest,
      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.cancel(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.zone = withPolling.zone
          }, options: options)
        return try extractStatus(op)
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: initialState,
        polling: options.pollingErrorPolicy ?? self.pollingErrorPolicy,
        backoff: options.pollingBackoffPolicy ?? self.pollingBackoffPolicy,
        poll: poll
      )
    }

    /// Deletes the specified, inactive resize request. Requests that are still
    /// active cannot be deleted. Deleting request does not delete instances that
    /// were provisioned previously.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_delete")
    public func delete(
      request: InstanceGroupManagerResizeRequestsClient.DeleteRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.delete(request: request, options: options)
    }

    /// Deletes the specified, inactive resize request. Requests that are still
    /// active cannot be deleted. Deleting request does not delete instances that
    /// were provisioned previously.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_delete")
    public func delete(
      withPolling: InstanceGroupManagerResizeRequestsClient.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.zone = withPolling.zone
          }, options: options)
        return try extractStatus(op)
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: initialState,
        polling: options.pollingErrorPolicy ?? self.pollingErrorPolicy,
        backoff: options.pollingBackoffPolicy ?? self.pollingBackoffPolicy,
        poll: poll
      )
    }

    /// Returns all of the details about the specified resize request.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_get")
    public func `get`(
      request: InstanceGroupManagerResizeRequestsClient.GetRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.InstanceGroupManagerResizeRequest {
      try await self.inner.`get`(request: request, options: options)
    }

    /// Creates a new resize request that starts provisioning VMs immediately
    /// or queues VM creation.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_insert")
    public func insert(
      request: InstanceGroupManagerResizeRequestsClient.InsertRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      try await self.inner.insert(request: request, options: options)
    }

    /// Creates a new resize request that starts provisioning VMs immediately
    /// or queues VM creation.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_insert")
    public func insert(
      withPolling: InstanceGroupManagerResizeRequestsClient.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.zone = withPolling.zone
          }, options: options)
        return try extractStatus(op)
      }
      return GoogleCloudGax._PollableOperationImpl(
        initialState: initialState,
        polling: options.pollingErrorPolicy ?? self.pollingErrorPolicy,
        backoff: options.pollingBackoffPolicy ?? self.pollingBackoffPolicy,
        poll: poll
      )
    }

    /// Retrieves a list of resize requests that are contained in the
    /// managed instance group.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_list")
    public func list(
      request: InstanceGroupManagerResizeRequestsClient.ListRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.InstanceGroupManagerResizeRequestsListResponse {
      try await self.inner.list(request: request, options: options)
    }

    /// Retrieves a list of resize requests that are contained in the
    /// managed instance group.
    ///
    /// @Snippet(path: "instanceGroupManagerResizeRequests_list")
    public func list(
      byItem: InstanceGroupManagerResizeRequestsClient.ListRequest,
      options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<InstanceGroupManagerResizeRequest, Swift.Error> {
      let listRpc = {
        (token: Swift.String) async throws
          -> GoogleCloudComputeV1.InstanceGroupManagerResizeRequestsListResponse in
        var request = byItem
        request.pageToken = token
        return try await self.list(request: request, options: options)
      }
      return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
    }

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

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

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

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

      /// See `InstanceGroupManagerResizeRequestsClient.`get``.
      func `get`(
        project: Swift.String,
        zone: Swift.String,
        instanceGroupManager: Swift.String,
        resizeRequest: Swift.String,
      ) async throws -> GoogleCloudComputeV1.InstanceGroupManagerResizeRequest

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

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

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

      /// See `InstanceGroupManagerResizeRequestsClient.list`.
      func list(
        project: Swift.String,
        zone: Swift.String,
        instanceGroupManager: Swift.String,
      ) throws -> any AsyncSequence<InstanceGroupManagerResizeRequest, Swift.Error>

      /// See `InstanceGroupManagerResizeRequestsClient.cancel`.
      func cancel(
        request: InstanceGroupManagerResizeRequestsClient.CancelRequest,
        options: GoogleCloudGax.RequestOptions
      ) async throws -> GoogleCloudComputeV1.Operation

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

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

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

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

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

  // Default implementations
  extension Clients.InstanceGroupManagerResizeRequestsProtocol {
    public func cancel(request: InstanceGroupManagerResizeRequestsClient.CancelRequest) async throws
      -> GoogleCloudComputeV1.Operation
    {
      try await self.cancel(request: request, options: .init())
    }

    public func cancel(
      request: InstanceGroupManagerResizeRequestsClient.CancelRequest,
      options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudComputeV1.Operation {
      throw GoogleCloudGax.RequestError.unimplemented
    }

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

    public func cancel(
      withPolling: InstanceGroupManagerResizeRequestsClient.CancelRequest,
      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 cancel(
      project: Swift.String,
      zone: Swift.String,
      instanceGroupManager: Swift.String,
      resizeRequest: Swift.String,
    ) async throws -> any GoogleCloudGax.PollableOperation<GoogleCloudComputeV1.Operation> {
      let request = InstanceGroupManagerResizeRequestsClient.CancelRequest().with {
        $0.project = project
        $0.zone = zone
        $0.instanceGroupManager = instanceGroupManager
        $0.resizeRequest = resizeRequest
      }
      return try await self.cancel(withPolling: request)
    }

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

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

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

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

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

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

    public func `get`(
      project: Swift.String,
      zone: Swift.String,
      instanceGroupManager: Swift.String,
      resizeRequest: Swift.String,
    ) async throws -> GoogleCloudComputeV1.InstanceGroupManagerResizeRequest {
      let request = InstanceGroupManagerResizeRequestsClient.GetRequest().with {
        $0.project = project
        $0.zone = zone
        $0.instanceGroupManager = instanceGroupManager
        $0.resizeRequest = resizeRequest
      }
      return try await self.`get`(request: request)
    }

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

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

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

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

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

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

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

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

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

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

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