/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: e5d888426b1c
 */

import { workflowsArchiveWorkflow } from "../funcs/workflowsArchiveWorkflow.js";
import { workflowsExecuteWorkflow } from "../funcs/workflowsExecuteWorkflow.js";
import { workflowsExecuteWorkflowRegistration } from "../funcs/workflowsExecuteWorkflowRegistration.js";
import { workflowsGetWorkflow } from "../funcs/workflowsGetWorkflow.js";
import { workflowsGetWorkflowRegistration } from "../funcs/workflowsGetWorkflowRegistration.js";
import { workflowsGetWorkflowRegistrations } from "../funcs/workflowsGetWorkflowRegistrations.js";
import { workflowsGetWorkflows } from "../funcs/workflowsGetWorkflows.js";
import { workflowsUnarchiveWorkflow } from "../funcs/workflowsUnarchiveWorkflow.js";
import { workflowsUpdateWorkflow } from "../funcs/workflowsUpdateWorkflow.js";
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
import * as components from "../models/components/index.js";
import * as operations from "../models/operations/index.js";
import { unwrapAsync } from "../types/fp.js";
import { PageIterator, unwrapResultIterator } from "../types/operations.js";
import { Deployments } from "./deployments.js";
import { Executions } from "./executions.js";
import { Metrics } from "./metrics.js";
import { Runs } from "./runs.js";
import { Schedules } from "./schedules.js";
import { WorkflowsEvents } from "./workflowsevents.js";

export class Workflows extends ClientSDK {
  private _executions?: Executions;
  get executions(): Executions {
    return (this._executions ??= new Executions(this._options));
  }

  private _metrics?: Metrics;
  get metrics(): Metrics {
    return (this._metrics ??= new Metrics(this._options));
  }

  private _runs?: Runs;
  get runs(): Runs {
    return (this._runs ??= new Runs(this._options));
  }

  private _schedules?: Schedules;
  get schedules(): Schedules {
    return (this._schedules ??= new Schedules(this._options));
  }

  private _events?: WorkflowsEvents;
  get events(): WorkflowsEvents {
    return (this._events ??= new WorkflowsEvents(this._options));
  }

  private _deployments?: Deployments;
  get deployments(): Deployments {
    return (this._deployments ??= new Deployments(this._options));
  }

  /**
   * Get Workflows
   */
  async getWorkflows(
    request?: operations.GetWorkflowsV1WorkflowsGetRequest | undefined,
    options?: RequestOptions,
  ): Promise<
    PageIterator<
      operations.GetWorkflowsV1WorkflowsGetResponse,
      { cursor: string }
    >
  > {
    return unwrapResultIterator(workflowsGetWorkflows(
      this,
      request,
      options,
    ));
  }

  /**
   * Get Workflow Registrations
   */
  async getWorkflowRegistrations(
    request?:
      | operations.GetWorkflowRegistrationsV1WorkflowsRegistrationsGetRequest
      | undefined,
    options?: RequestOptions,
  ): Promise<components.WorkflowRegistrationListResponse> {
    return unwrapAsync(workflowsGetWorkflowRegistrations(
      this,
      request,
      options,
    ));
  }

  /**
   * Execute Workflow
   */
  async executeWorkflow(
    request:
      operations.ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest,
    options?: RequestOptions,
  ): Promise<
    operations.ResponseExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePost
  > {
    return unwrapAsync(workflowsExecuteWorkflow(
      this,
      request,
      options,
    ));
  }

  /**
   * Execute Workflow Registration
   *
   * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  async executeWorkflowRegistration(
    request:
      operations.ExecuteWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePostRequest,
    options?: RequestOptions,
  ): Promise<
    operations.ResponseExecuteWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePost
  > {
    return unwrapAsync(workflowsExecuteWorkflowRegistration(
      this,
      request,
      options,
    ));
  }

  /**
   * Get Workflow
   */
  async getWorkflow(
    request: operations.GetWorkflowV1WorkflowsWorkflowIdentifierGetRequest,
    options?: RequestOptions,
  ): Promise<components.WorkflowGetResponse> {
    return unwrapAsync(workflowsGetWorkflow(
      this,
      request,
      options,
    ));
  }

  /**
   * Update Workflow
   */
  async updateWorkflow(
    request: operations.UpdateWorkflowV1WorkflowsWorkflowIdentifierPutRequest,
    options?: RequestOptions,
  ): Promise<components.WorkflowUpdateResponse> {
    return unwrapAsync(workflowsUpdateWorkflow(
      this,
      request,
      options,
    ));
  }

  /**
   * Get Workflow Registration
   */
  async getWorkflowRegistration(
    request:
      operations.GetWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdGetRequest,
    options?: RequestOptions,
  ): Promise<components.WorkflowRegistrationGetResponse> {
    return unwrapAsync(workflowsGetWorkflowRegistration(
      this,
      request,
      options,
    ));
  }

  /**
   * Archive Workflow
   */
  async archiveWorkflow(
    request:
      operations.ArchiveWorkflowV1WorkflowsWorkflowIdentifierArchivePutRequest,
    options?: RequestOptions,
  ): Promise<components.WorkflowArchiveResponse> {
    return unwrapAsync(workflowsArchiveWorkflow(
      this,
      request,
      options,
    ));
  }

  /**
   * Unarchive Workflow
   */
  async unarchiveWorkflow(
    request:
      operations.UnarchiveWorkflowV1WorkflowsWorkflowIdentifierUnarchivePutRequest,
    options?: RequestOptions,
  ): Promise<components.WorkflowUnarchiveResponse> {
    return unwrapAsync(workflowsUnarchiveWorkflow(
      this,
      request,
      options,
    ));
  }
}
