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

import { butlerGetTasks } from "../funcs/butlerGetTasks.js";
import { butlerStartTask } from "../funcs/butlerStartTask.js";
import { butlerStartTasks } from "../funcs/butlerStartTasks.js";
import { butlerStopTask } from "../funcs/butlerStopTask.js";
import { butlerStopTasks } from "../funcs/butlerStopTasks.js";
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
import * as operations from "./models/operations/index.js";
import { unwrapAsync } from "./types/fp.js";

export class Butler extends ClientSDK {
  /**
   * Stop all Butler tasks
   *
   * @remarks
   * This endpoint will stop all currently running tasks and remove any scheduled tasks from the queue.
   */
  async stopTasks(
    options?: RequestOptions,
  ): Promise<operations.StopTasksResponse> {
    return unwrapAsync(butlerStopTasks(
      this,
      options,
    ));
  }

  /**
   * Get all Butler tasks
   *
   * @remarks
   * Get the list of butler tasks and their scheduling
   */
  async getTasks(
    options?: RequestOptions,
  ): Promise<operations.GetTasksResponse> {
    return unwrapAsync(butlerGetTasks(
      this,
      options,
    ));
  }

  /**
   * Start all Butler tasks
   *
   * @remarks
   * This endpoint will attempt to start all Butler tasks that are enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria:
   *
   *   1. Any tasks not scheduled to run on the current day will be skipped.
   *   2. If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately.
   *   3. If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
   *   4. If we are outside the configured window, the task will start immediately.
   */
  async startTasks(
    options?: RequestOptions,
  ): Promise<operations.StartTasksResponse> {
    return unwrapAsync(butlerStartTasks(
      this,
      options,
    ));
  }

  /**
   * Stop a single Butler task
   *
   * @remarks
   * This endpoint will stop a currently running task by name, or remove it from the list of scheduled tasks if it exists
   */
  async stopTask(
    request: operations.StopTaskRequest,
    options?: RequestOptions,
  ): Promise<operations.StopTaskResponse> {
    return unwrapAsync(butlerStopTask(
      this,
      request,
      options,
    ));
  }

  /**
   * Start a single Butler task
   *
   * @remarks
   * This endpoint will attempt to start a specific Butler task by name.
   */
  async startTask(
    request: operations.StartTaskRequest,
    options?: RequestOptions,
  ): Promise<operations.StartTaskResponse> {
    return unwrapAsync(butlerStartTask(
      this,
      request,
      options,
    ));
  }
}
