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

/// Executions is used to start and manage running instances of
/// [Workflows][google.cloud.workflows.v1.Workflow] called executions.
///
/// @Snippet(path: "ExecutionsQuickstart")
public class ExecutionsClient: Clients.ExecutionsProtocol {
  let inner: any Clients.ExecutionsStub

  /// Creates a new `ExecutionsClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.ExecutionsStub = try Clients.ExecutionsTransport(options)
    inner = Clients.ExecutionsRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.ExecutionsLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Returns a list of executions which belong to the workflow with
  /// the given name. The method returns executions of all workflow
  /// revisions. Returned executions are ordered by their start time (newest
  /// first).
  ///
  /// @Snippet(path: "Executions_ListExecutions")
  public func listExecutions(
    request: ListExecutionsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.ListExecutionsResponse {
    try await self.inner.listExecutions(request: request, options: options)
  }

  /// Returns a list of executions which belong to the workflow with
  /// the given name. The method returns executions of all workflow
  /// revisions. Returned executions are ordered by their start time (newest
  /// first).
  ///
  /// @Snippet(path: "Executions_ListExecutions")
  public func listExecutions(
    byItem: ListExecutionsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<Execution, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudWorkflowsExecutionsV1.ListExecutionsResponse
      in
      var request = byItem
      request.pageToken = token
      return try await self.listExecutions(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Creates a new execution using the latest revision of the given workflow.
  ///
  /// @Snippet(path: "Executions_CreateExecution")
  public func createExecution(
    request: CreateExecutionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    try await self.inner.createExecution(request: request, options: options)
  }

  /// Returns an execution of the given name.
  ///
  /// @Snippet(path: "Executions_GetExecution")
  public func getExecution(
    request: GetExecutionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    try await self.inner.getExecution(request: request, options: options)
  }

  /// Cancels an execution of the given name.
  ///
  /// @Snippet(path: "Executions_CancelExecution")
  public func cancelExecution(
    request: CancelExecutionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    try await self.inner.cancelExecution(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `ExecutionsClient`.
  ///
  /// To mock `ExecutionsClient` change your functions to receive
  /// `some ExecutionsProtocol` or `any ExecutionsProtocol`
  /// and pass a mock implementation in your tests.
  public protocol ExecutionsProtocol {
    /// See `ExecutionsClient.listExecutions`.
    func listExecutions(request: ListExecutionsRequest) async throws
      -> GoogleCloudWorkflowsExecutionsV1.ListExecutionsResponse

    /// See `ExecutionsClient.listExecutions`.
    func listExecutions(
      byItem: ListExecutionsRequest
    ) throws -> any AsyncSequence<Execution, Swift.Error>

    /// See `ExecutionsClient.listExecutions`.
    func listExecutions(
      parent: Swift.String,
    ) throws -> any AsyncSequence<Execution, Swift.Error>

    /// See `ExecutionsClient.createExecution`.
    func createExecution(request: CreateExecutionRequest) async throws
      -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.createExecution`.
    func createExecution(
      parent: Swift.String,
      execution: Execution?,
    ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.getExecution`.
    func getExecution(request: GetExecutionRequest) async throws
      -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.getExecution`.
    func getExecution(
      name: Swift.String,
    ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.cancelExecution`.
    func cancelExecution(request: CancelExecutionRequest) async throws
      -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.cancelExecution`.
    func cancelExecution(
      name: Swift.String,
    ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.listExecutions`.
    func listExecutions(
      request: ListExecutionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudWorkflowsExecutionsV1.ListExecutionsResponse

    /// See `ExecutionsClient.listExecutions`.
    func listExecutions(
      byItem: ListExecutionsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<Execution, Swift.Error>

    /// See `ExecutionsClient.createExecution`.
    func createExecution(
      request: CreateExecutionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.getExecution`.
    func getExecution(
      request: GetExecutionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution

    /// See `ExecutionsClient.cancelExecution`.
    func cancelExecution(
      request: CancelExecutionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution
  }
}

// Default implementations
extension Clients.ExecutionsProtocol {
  public func listExecutions(request: ListExecutionsRequest) async throws
    -> GoogleCloudWorkflowsExecutionsV1.ListExecutionsResponse
  {
    try await self.listExecutions(request: request, options: .init())
  }

  public func listExecutions(
    request: ListExecutionsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.ListExecutionsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listExecutions(
    byItem: ListExecutionsRequest
  ) throws -> any AsyncSequence<Execution, Swift.Error> {
    try self.listExecutions(byItem: byItem, options: .init())
  }

  public func listExecutions(
    byItem: ListExecutionsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<Execution, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudWorkflowsExecutionsV1.ListExecutionsResponse
      in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listExecutions(
    parent: Swift.String,
  ) throws -> any AsyncSequence<Execution, Swift.Error> {
    let request = ListExecutionsRequest().with {
      $0.parent = parent
    }
    return try self.listExecutions(byItem: request)
  }

  public func createExecution(request: CreateExecutionRequest) async throws
    -> GoogleCloudWorkflowsExecutionsV1.Execution
  {
    try await self.createExecution(request: request, options: .init())
  }

  public func createExecution(
    request: CreateExecutionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func createExecution(
    parent: Swift.String,
    execution: Execution?,
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    let request = CreateExecutionRequest().with {
      $0.parent = parent
      $0.execution = execution
    }
    return try await self.createExecution(request: request)
  }

  public func getExecution(request: GetExecutionRequest) async throws
    -> GoogleCloudWorkflowsExecutionsV1.Execution
  {
    try await self.getExecution(request: request, options: .init())
  }

  public func getExecution(
    request: GetExecutionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getExecution(
    name: Swift.String,
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    let request = GetExecutionRequest().with {
      $0.name = name
    }
    return try await self.getExecution(request: request)
  }

  public func cancelExecution(request: CancelExecutionRequest) async throws
    -> GoogleCloudWorkflowsExecutionsV1.Execution
  {
    try await self.cancelExecution(request: request, options: .init())
  }

  public func cancelExecution(
    request: CancelExecutionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func cancelExecution(
    name: Swift.String,
  ) async throws -> GoogleCloudWorkflowsExecutionsV1.Execution {
    let request = CancelExecutionRequest().with {
      $0.name = name
    }
    return try await self.cancelExecution(request: request)
  }
}
