/* tslint:disable */
/* eslint-disable */
/**
 * Fabro Run API
 * HTTP API for managing Fabro workflow run executions.
 *
 * The version of the OpenAPI document: 0.2.0
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import type { Configuration } from '../configuration';
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';
// Some imports not used depending on template conditions
// @ts-ignore
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction, replaceWithSerializableTypeIfNeeded } from '../common';
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base';
// @ts-ignore
import type { ErrorResponse } from '../models';
// @ts-ignore
import type { PaginatedRunList } from '../models';
// @ts-ignore
import type { PaginatedWorkflowListResponse } from '../models';
// @ts-ignore
import type { WorkflowDetailResponse } from '../models';
/**
 * WorkflowsApi - axios parameter creator
 */
export const WorkflowsApiAxiosParamCreator = function (configuration?: Configuration) {
    return {
        /**
         * Returns durable runs associated with one workflow.
         * @summary List workflow runs
         * @param {string} name Workflow slug or name.
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listWorkflowRuns: async (name: string, pageLimit?: number, pageOffset?: number, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'name' is not null or undefined
            assertParamExists('listWorkflowRuns', 'name', name)
            const localVarPath = `/api/v1/workflows/{name}/runs`
                .replace(`{${"name"}}`, encodeURIComponent(String(name)));
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
            let baseOptions;
            if (configuration) {
                baseOptions = configuration.baseOptions;
            }

            const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication SessionCookie required

            // authentication BearerAuth required
            // http bearer authentication required
            await setBearerAuthToObject(localVarHeaderParameter, configuration)

            if (pageLimit !== undefined) {
                localVarQueryParameter['page[limit]'] = pageLimit;
            }

            if (pageOffset !== undefined) {
                localVarQueryParameter['page[offset]'] = pageOffset;
            }

            localVarHeaderParameter['Accept'] = 'application/json';

            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
        /**
         * Returns workflow definitions available to the browser workflow pages. Real-mode servers may return 501 until workflow cataloging is implemented.
         * @summary List workflows
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listWorkflows: async (pageLimit?: number, pageOffset?: number, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            const localVarPath = `/api/v1/workflows`;
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
            let baseOptions;
            if (configuration) {
                baseOptions = configuration.baseOptions;
            }

            const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication SessionCookie required

            // authentication BearerAuth required
            // http bearer authentication required
            await setBearerAuthToObject(localVarHeaderParameter, configuration)

            if (pageLimit !== undefined) {
                localVarQueryParameter['page[limit]'] = pageLimit;
            }

            if (pageOffset !== undefined) {
                localVarQueryParameter['page[offset]'] = pageOffset;
            }

            localVarHeaderParameter['Accept'] = 'application/json';

            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
        /**
         * Returns a single workflow definition and its dense settings snapshot.
         * @summary Retrieve workflow
         * @param {string} name Workflow slug or name.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        retrieveWorkflow: async (name: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'name' is not null or undefined
            assertParamExists('retrieveWorkflow', 'name', name)
            const localVarPath = `/api/v1/workflows/{name}`
                .replace(`{${"name"}}`, encodeURIComponent(String(name)));
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
            let baseOptions;
            if (configuration) {
                baseOptions = configuration.baseOptions;
            }

            const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication SessionCookie required

            // authentication BearerAuth required
            // http bearer authentication required
            await setBearerAuthToObject(localVarHeaderParameter, configuration)

            localVarHeaderParameter['Accept'] = 'application/json';

            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
    }
};

/**
 * WorkflowsApi - functional programming interface
 */
export const WorkflowsApiFp = function(configuration?: Configuration) {
    const localVarAxiosParamCreator = WorkflowsApiAxiosParamCreator(configuration)
    return {
        /**
         * Returns durable runs associated with one workflow.
         * @summary List workflow runs
         * @param {string} name Workflow slug or name.
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async listWorkflowRuns(name: string, pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<PaginatedRunList>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.listWorkflowRuns(name, pageLimit, pageOffset, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['WorkflowsApi.listWorkflowRuns']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Returns workflow definitions available to the browser workflow pages. Real-mode servers may return 501 until workflow cataloging is implemented.
         * @summary List workflows
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async listWorkflows(pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<PaginatedWorkflowListResponse>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.listWorkflows(pageLimit, pageOffset, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['WorkflowsApi.listWorkflows']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Returns a single workflow definition and its dense settings snapshot.
         * @summary Retrieve workflow
         * @param {string} name Workflow slug or name.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async retrieveWorkflow(name: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<WorkflowDetailResponse>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.retrieveWorkflow(name, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['WorkflowsApi.retrieveWorkflow']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
    }
};

/**
 * WorkflowsApi - factory interface
 */
export const WorkflowsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
    const localVarFp = WorkflowsApiFp(configuration)
    return {
        /**
         * Returns durable runs associated with one workflow.
         * @summary List workflow runs
         * @param {string} name Workflow slug or name.
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listWorkflowRuns(name: string, pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig): AxiosPromise<PaginatedRunList> {
            return localVarFp.listWorkflowRuns(name, pageLimit, pageOffset, options).then((request) => request(axios, basePath));
        },
        /**
         * Returns workflow definitions available to the browser workflow pages. Real-mode servers may return 501 until workflow cataloging is implemented.
         * @summary List workflows
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listWorkflows(pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig): AxiosPromise<PaginatedWorkflowListResponse> {
            return localVarFp.listWorkflows(pageLimit, pageOffset, options).then((request) => request(axios, basePath));
        },
        /**
         * Returns a single workflow definition and its dense settings snapshot.
         * @summary Retrieve workflow
         * @param {string} name Workflow slug or name.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        retrieveWorkflow(name: string, options?: RawAxiosRequestConfig): AxiosPromise<WorkflowDetailResponse> {
            return localVarFp.retrieveWorkflow(name, options).then((request) => request(axios, basePath));
        },
    };
};

/**
 * WorkflowsApi - object-oriented interface
 */
export class WorkflowsApi extends BaseAPI {
    /**
     * Returns durable runs associated with one workflow.
     * @summary List workflow runs
     * @param {string} name Workflow slug or name.
     * @param {number} [pageLimit] Maximum number of items to return per page.
     * @param {number} [pageOffset] Number of items to skip before returning results.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public listWorkflowRuns(name: string, pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig) {
        return WorkflowsApiFp(this.configuration).listWorkflowRuns(name, pageLimit, pageOffset, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Returns workflow definitions available to the browser workflow pages. Real-mode servers may return 501 until workflow cataloging is implemented.
     * @summary List workflows
     * @param {number} [pageLimit] Maximum number of items to return per page.
     * @param {number} [pageOffset] Number of items to skip before returning results.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public listWorkflows(pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig) {
        return WorkflowsApiFp(this.configuration).listWorkflows(pageLimit, pageOffset, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Returns a single workflow definition and its dense settings snapshot.
     * @summary Retrieve workflow
     * @param {string} name Workflow slug or name.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public retrieveWorkflow(name: string, options?: RawAxiosRequestConfig) {
        return WorkflowsApiFp(this.configuration).retrieveWorkflow(name, options).then((request) => request(this.axios, this.basePath));
    }
}
