/* 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 { PaginatedRunCommitList } from '../models';
// @ts-ignore
import type { PaginatedRunFileList } from '../models';
// @ts-ignore
import type { RunBilling } from '../models';
/**
 * RunOutputsApi - axios parameter creator
 */
export const RunOutputsApiAxiosParamCreator = function (configuration?: Configuration) {
    return {
        /**
         * Returns commits on the run branch since the run\'s base SHA, sourced directly from sandbox Git.  The list uses first-parent chronological history and is capped by `limit` (default and maximum: 100). Commit data is Git-authoritative; Fabro-generated commit messages are not required for correctness.
         * @summary List Run Commits
         * @param {string} id Unique run identifier (ULID).
         * @param {number} [limit] Maximum number of commits to return. Defaults to 100 and is capped at 100.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listRunCommits: async (id: string, limit?: number, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'id' is not null or undefined
            assertParamExists('listRunCommits', 'id', id)
            const localVarPath = `/api/v1/runs/{id}/commits`
                .replace(`{${"id"}}`, encodeURIComponent(String(id)));
            // 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 (limit !== undefined) {
                localVarQueryParameter['limit'] = limit;
            }

            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 the set of file changes produced by a run as a list of before/after diffs.  While the run\'s sandbox is reachable, diffs are resolved live against the sandbox working tree at the current HEAD. Degraded responses keep the same `data: FileDiff[]` shape. File contents are null on every entry; non-sensitive non-flagged entries include `unified_patch`, while sensitive / binary / symlink / submodule / truncated entries render through the same placeholder flags used by the live path.  Responses are bounded by per-file (256 KiB / 20k lines), per-run aggregate (5 MiB), and per-request (200 files) caps. Files exceeding a cap are returned with `truncated: true` and empty `contents`. Sensitive paths (credentials, keys) are elided with `sensitive: true` and empty `contents`.
         * @summary List Run Files Changed
         * @param {string} id Unique run identifier (ULID).
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {ListRunFilesScopeEnum} [scope] Diff scope to return. Defaults to committed changes only. Sandbox-backed responses honor all scopes for tracked files; untracked files are excluded. Final-patch fallback responses always represent the stored committed/final diff.
         * @param {string} [fromSha] Explicit start SHA for a commit-range diff. Must be supplied together with &#x60;to_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
         * @param {string} [toSha] Explicit end SHA for a commit-range diff. Must be supplied together with &#x60;from_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listRunFiles: async (id: string, pageLimit?: number, pageOffset?: number, scope?: ListRunFilesScopeEnum, fromSha?: string, toSha?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'id' is not null or undefined
            assertParamExists('listRunFiles', 'id', id)
            const localVarPath = `/api/v1/runs/{id}/files`
                .replace(`{${"id"}}`, encodeURIComponent(String(id)));
            // 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;
            }

            if (scope !== undefined) {
                localVarQueryParameter['scope'] = scope;
            }

            if (fromSha !== undefined) {
                localVarQueryParameter['from_sha'] = fromSha;
            }

            if (toSha !== undefined) {
                localVarQueryParameter['to_sha'] = toSha;
            }

            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 token counts and billed totals broken down by stage and model for a specific run.
         * @summary Retrieve Run Billing
         * @param {string} id Unique run identifier (ULID).
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        retrieveRunBilling: async (id: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'id' is not null or undefined
            assertParamExists('retrieveRunBilling', 'id', id)
            const localVarPath = `/api/v1/runs/{id}/billing`
                .replace(`{${"id"}}`, encodeURIComponent(String(id)));
            // 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,
            };
        },
    }
};

/**
 * RunOutputsApi - functional programming interface
 */
export const RunOutputsApiFp = function(configuration?: Configuration) {
    const localVarAxiosParamCreator = RunOutputsApiAxiosParamCreator(configuration)
    return {
        /**
         * Returns commits on the run branch since the run\'s base SHA, sourced directly from sandbox Git.  The list uses first-parent chronological history and is capped by `limit` (default and maximum: 100). Commit data is Git-authoritative; Fabro-generated commit messages are not required for correctness.
         * @summary List Run Commits
         * @param {string} id Unique run identifier (ULID).
         * @param {number} [limit] Maximum number of commits to return. Defaults to 100 and is capped at 100.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async listRunCommits(id: string, limit?: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<PaginatedRunCommitList>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.listRunCommits(id, limit, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['RunOutputsApi.listRunCommits']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Returns the set of file changes produced by a run as a list of before/after diffs.  While the run\'s sandbox is reachable, diffs are resolved live against the sandbox working tree at the current HEAD. Degraded responses keep the same `data: FileDiff[]` shape. File contents are null on every entry; non-sensitive non-flagged entries include `unified_patch`, while sensitive / binary / symlink / submodule / truncated entries render through the same placeholder flags used by the live path.  Responses are bounded by per-file (256 KiB / 20k lines), per-run aggregate (5 MiB), and per-request (200 files) caps. Files exceeding a cap are returned with `truncated: true` and empty `contents`. Sensitive paths (credentials, keys) are elided with `sensitive: true` and empty `contents`.
         * @summary List Run Files Changed
         * @param {string} id Unique run identifier (ULID).
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {ListRunFilesScopeEnum} [scope] Diff scope to return. Defaults to committed changes only. Sandbox-backed responses honor all scopes for tracked files; untracked files are excluded. Final-patch fallback responses always represent the stored committed/final diff.
         * @param {string} [fromSha] Explicit start SHA for a commit-range diff. Must be supplied together with &#x60;to_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
         * @param {string} [toSha] Explicit end SHA for a commit-range diff. Must be supplied together with &#x60;from_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async listRunFiles(id: string, pageLimit?: number, pageOffset?: number, scope?: ListRunFilesScopeEnum, fromSha?: string, toSha?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<PaginatedRunFileList>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.listRunFiles(id, pageLimit, pageOffset, scope, fromSha, toSha, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['RunOutputsApi.listRunFiles']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Returns token counts and billed totals broken down by stage and model for a specific run.
         * @summary Retrieve Run Billing
         * @param {string} id Unique run identifier (ULID).
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async retrieveRunBilling(id: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RunBilling>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.retrieveRunBilling(id, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['RunOutputsApi.retrieveRunBilling']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
    }
};

/**
 * RunOutputsApi - factory interface
 */
export const RunOutputsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
    const localVarFp = RunOutputsApiFp(configuration)
    return {
        /**
         * Returns commits on the run branch since the run\'s base SHA, sourced directly from sandbox Git.  The list uses first-parent chronological history and is capped by `limit` (default and maximum: 100). Commit data is Git-authoritative; Fabro-generated commit messages are not required for correctness.
         * @summary List Run Commits
         * @param {string} id Unique run identifier (ULID).
         * @param {number} [limit] Maximum number of commits to return. Defaults to 100 and is capped at 100.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listRunCommits(id: string, limit?: number, options?: RawAxiosRequestConfig): AxiosPromise<PaginatedRunCommitList> {
            return localVarFp.listRunCommits(id, limit, options).then((request) => request(axios, basePath));
        },
        /**
         * Returns the set of file changes produced by a run as a list of before/after diffs.  While the run\'s sandbox is reachable, diffs are resolved live against the sandbox working tree at the current HEAD. Degraded responses keep the same `data: FileDiff[]` shape. File contents are null on every entry; non-sensitive non-flagged entries include `unified_patch`, while sensitive / binary / symlink / submodule / truncated entries render through the same placeholder flags used by the live path.  Responses are bounded by per-file (256 KiB / 20k lines), per-run aggregate (5 MiB), and per-request (200 files) caps. Files exceeding a cap are returned with `truncated: true` and empty `contents`. Sensitive paths (credentials, keys) are elided with `sensitive: true` and empty `contents`.
         * @summary List Run Files Changed
         * @param {string} id Unique run identifier (ULID).
         * @param {number} [pageLimit] Maximum number of items to return per page.
         * @param {number} [pageOffset] Number of items to skip before returning results.
         * @param {ListRunFilesScopeEnum} [scope] Diff scope to return. Defaults to committed changes only. Sandbox-backed responses honor all scopes for tracked files; untracked files are excluded. Final-patch fallback responses always represent the stored committed/final diff.
         * @param {string} [fromSha] Explicit start SHA for a commit-range diff. Must be supplied together with &#x60;to_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
         * @param {string} [toSha] Explicit end SHA for a commit-range diff. Must be supplied together with &#x60;from_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listRunFiles(id: string, pageLimit?: number, pageOffset?: number, scope?: ListRunFilesScopeEnum, fromSha?: string, toSha?: string, options?: RawAxiosRequestConfig): AxiosPromise<PaginatedRunFileList> {
            return localVarFp.listRunFiles(id, pageLimit, pageOffset, scope, fromSha, toSha, options).then((request) => request(axios, basePath));
        },
        /**
         * Returns token counts and billed totals broken down by stage and model for a specific run.
         * @summary Retrieve Run Billing
         * @param {string} id Unique run identifier (ULID).
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        retrieveRunBilling(id: string, options?: RawAxiosRequestConfig): AxiosPromise<RunBilling> {
            return localVarFp.retrieveRunBilling(id, options).then((request) => request(axios, basePath));
        },
    };
};

/**
 * RunOutputsApi - object-oriented interface
 */
export class RunOutputsApi extends BaseAPI {
    /**
     * Returns commits on the run branch since the run\'s base SHA, sourced directly from sandbox Git.  The list uses first-parent chronological history and is capped by `limit` (default and maximum: 100). Commit data is Git-authoritative; Fabro-generated commit messages are not required for correctness.
     * @summary List Run Commits
     * @param {string} id Unique run identifier (ULID).
     * @param {number} [limit] Maximum number of commits to return. Defaults to 100 and is capped at 100.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public listRunCommits(id: string, limit?: number, options?: RawAxiosRequestConfig) {
        return RunOutputsApiFp(this.configuration).listRunCommits(id, limit, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Returns the set of file changes produced by a run as a list of before/after diffs.  While the run\'s sandbox is reachable, diffs are resolved live against the sandbox working tree at the current HEAD. Degraded responses keep the same `data: FileDiff[]` shape. File contents are null on every entry; non-sensitive non-flagged entries include `unified_patch`, while sensitive / binary / symlink / submodule / truncated entries render through the same placeholder flags used by the live path.  Responses are bounded by per-file (256 KiB / 20k lines), per-run aggregate (5 MiB), and per-request (200 files) caps. Files exceeding a cap are returned with `truncated: true` and empty `contents`. Sensitive paths (credentials, keys) are elided with `sensitive: true` and empty `contents`.
     * @summary List Run Files Changed
     * @param {string} id Unique run identifier (ULID).
     * @param {number} [pageLimit] Maximum number of items to return per page.
     * @param {number} [pageOffset] Number of items to skip before returning results.
     * @param {ListRunFilesScopeEnum} [scope] Diff scope to return. Defaults to committed changes only. Sandbox-backed responses honor all scopes for tracked files; untracked files are excluded. Final-patch fallback responses always represent the stored committed/final diff.
     * @param {string} [fromSha] Explicit start SHA for a commit-range diff. Must be supplied together with &#x60;to_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
     * @param {string} [toSha] Explicit end SHA for a commit-range diff. Must be supplied together with &#x60;from_sha&#x60;; when present, &#x60;scope&#x60; must be omitted and the response scope is &#x60;range&#x60;.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public listRunFiles(id: string, pageLimit?: number, pageOffset?: number, scope?: ListRunFilesScopeEnum, fromSha?: string, toSha?: string, options?: RawAxiosRequestConfig) {
        return RunOutputsApiFp(this.configuration).listRunFiles(id, pageLimit, pageOffset, scope, fromSha, toSha, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Returns token counts and billed totals broken down by stage and model for a specific run.
     * @summary Retrieve Run Billing
     * @param {string} id Unique run identifier (ULID).
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public retrieveRunBilling(id: string, options?: RawAxiosRequestConfig) {
        return RunOutputsApiFp(this.configuration).retrieveRunBilling(id, options).then((request) => request(this.axios, this.basePath));
    }
}

export const ListRunFilesScopeEnum = {
    COMMITTED: 'committed',
    UNCOMMITTED: 'uncommitted',
    ALL: 'all'
} as const;
export type ListRunFilesScopeEnum = typeof ListRunFilesScopeEnum[keyof typeof ListRunFilesScopeEnum];
