/* tslint:disable */
/* eslint-disable */
/**
 * Fabro Run API
 * HTTP API for managing Fabro workflow run executions.
 *
 * The version of the OpenAPI document: 0.1.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 { CreateSessionRequest } from '../models';
// @ts-ignore
import type { CreateSessionResponse } from '../models';
// @ts-ignore
import type { ErrorResponse } from '../models';
// @ts-ignore
import type { PaginatedSessionList } from '../models';
// @ts-ignore
import type { SendMessageRequest } from '../models';
// @ts-ignore
import type { SendMessageResponse } from '../models';
// @ts-ignore
import type { SessionDetail } from '../models';
/**
 * SessionsApi - axios parameter creator
 */
export const SessionsApiAxiosParamCreator = function (configuration?: Configuration) {
    return {
        /**
         * Start a new interactive chat session. The initial user prompt is required; a model may optionally be specified.
         * @summary Create Session
         * @param {CreateSessionRequest} createSessionRequest 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        createSession: async (createSessionRequest: CreateSessionRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'createSessionRequest' is not null or undefined
            assertParamExists('createSession', 'createSessionRequest', createSessionRequest)
            const localVarPath = `/sessions`;
            // 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: 'POST', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication mTLS required
            await setApiKeyToObject(localVarHeaderParameter, "X-mTLS-Client-CN", configuration)

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

            localVarHeaderParameter['Content-Type'] = 'application/json';
            localVarHeaderParameter['Accept'] = 'application/json';

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

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
        /**
         * Returns sessions ordered by recency (newest first).
         * @summary List Sessions
         * @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}
         */
        listSessions: async (pageLimit?: number, pageOffset?: number, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            const localVarPath = `/sessions`;
            // 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 mTLS required
            await setApiKeyToObject(localVarHeaderParameter, "X-mTLS-Client-CN", configuration)

            // 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 the full session detail including all conversation turns.
         * @summary Retrieve Session
         * @param {string} id Unique session identifier.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        retrieveSession: async (id: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'id' is not null or undefined
            assertParamExists('retrieveSession', 'id', id)
            const localVarPath = `/sessions/{id}`
                .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 mTLS required
            await setApiKeyToObject(localVarHeaderParameter, "X-mTLS-Client-CN", configuration)

            // 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,
            };
        },
        /**
         * Append a user message to an existing session. The server will process it and produce assistant and tool turns asynchronously via the event stream.
         * @summary Send Session Message
         * @param {string} id Unique session identifier.
         * @param {SendMessageRequest} sendMessageRequest 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        sendSessionMessage: async (id: string, sendMessageRequest: SendMessageRequest, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'id' is not null or undefined
            assertParamExists('sendSessionMessage', 'id', id)
            // verify required parameter 'sendMessageRequest' is not null or undefined
            assertParamExists('sendSessionMessage', 'sendMessageRequest', sendMessageRequest)
            const localVarPath = `/sessions/{id}/messages`
                .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: 'POST', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication mTLS required
            await setApiKeyToObject(localVarHeaderParameter, "X-mTLS-Client-CN", configuration)

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

            localVarHeaderParameter['Content-Type'] = 'application/json';
            localVarHeaderParameter['Accept'] = 'application/json';

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

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
        /**
         * Opens a server-sent event (SSE) stream for real-time session updates.  Each SSE frame includes a sequential numeric `id:` field that supports resumption via the `Last-Event-ID` request header.  The stream emits the following SSE event types:  - `event: content_delta` — data: `{\"delta\": \"...\"}` (incremental text chunk) - `event: assistant_turn` — data: `AssistantTurn` JSON object - `event: tool_turn` — data: `ToolTurn` JSON object - `event: done` — data: `{}` (stream complete) - `event: error` — data: `{\"message\": \"...\"}` (error occurred)  Each SSE frame has an `id:` line (sequential integer), an `event:` line (the event type), and a `data:` line (the JSON payload). 
         * @summary Stream Session Events
         * @param {string} id Unique session identifier.
         * @param {string} [lastEventID] SSE reconnection header. When provided, the server resumes the stream after the event with this ID. IDs are 0-based sequential integers assigned to each emitted SSE frame. 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        streamSessionEvents: async (id: string, lastEventID?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'id' is not null or undefined
            assertParamExists('streamSessionEvents', 'id', id)
            const localVarPath = `/sessions/{id}/events`
                .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 mTLS required
            await setApiKeyToObject(localVarHeaderParameter, "X-mTLS-Client-CN", configuration)

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

            localVarHeaderParameter['Accept'] = 'text/event-stream,application/json';

            if (lastEventID != null) {
                localVarHeaderParameter['Last-Event-ID'] = String(lastEventID);
            }
            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

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

/**
 * SessionsApi - functional programming interface
 */
export const SessionsApiFp = function(configuration?: Configuration) {
    const localVarAxiosParamCreator = SessionsApiAxiosParamCreator(configuration)
    return {
        /**
         * Start a new interactive chat session. The initial user prompt is required; a model may optionally be specified.
         * @summary Create Session
         * @param {CreateSessionRequest} createSessionRequest 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async createSession(createSessionRequest: CreateSessionRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CreateSessionResponse>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.createSession(createSessionRequest, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['SessionsApi.createSession']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Returns sessions ordered by recency (newest first).
         * @summary List Sessions
         * @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 listSessions(pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<PaginatedSessionList>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.listSessions(pageLimit, pageOffset, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['SessionsApi.listSessions']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Returns the full session detail including all conversation turns.
         * @summary Retrieve Session
         * @param {string} id Unique session identifier.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async retrieveSession(id: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<SessionDetail>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.retrieveSession(id, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['SessionsApi.retrieveSession']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Append a user message to an existing session. The server will process it and produce assistant and tool turns asynchronously via the event stream.
         * @summary Send Session Message
         * @param {string} id Unique session identifier.
         * @param {SendMessageRequest} sendMessageRequest 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async sendSessionMessage(id: string, sendMessageRequest: SendMessageRequest, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<SendMessageResponse>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.sendSessionMessage(id, sendMessageRequest, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['SessionsApi.sendSessionMessage']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * Opens a server-sent event (SSE) stream for real-time session updates.  Each SSE frame includes a sequential numeric `id:` field that supports resumption via the `Last-Event-ID` request header.  The stream emits the following SSE event types:  - `event: content_delta` — data: `{\"delta\": \"...\"}` (incremental text chunk) - `event: assistant_turn` — data: `AssistantTurn` JSON object - `event: tool_turn` — data: `ToolTurn` JSON object - `event: done` — data: `{}` (stream complete) - `event: error` — data: `{\"message\": \"...\"}` (error occurred)  Each SSE frame has an `id:` line (sequential integer), an `event:` line (the event type), and a `data:` line (the JSON payload). 
         * @summary Stream Session Events
         * @param {string} id Unique session identifier.
         * @param {string} [lastEventID] SSE reconnection header. When provided, the server resumes the stream after the event with this ID. IDs are 0-based sequential integers assigned to each emitted SSE frame. 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async streamSessionEvents(id: string, lastEventID?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<string>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.streamSessionEvents(id, lastEventID, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['SessionsApi.streamSessionEvents']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
    }
};

/**
 * SessionsApi - factory interface
 */
export const SessionsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
    const localVarFp = SessionsApiFp(configuration)
    return {
        /**
         * Start a new interactive chat session. The initial user prompt is required; a model may optionally be specified.
         * @summary Create Session
         * @param {CreateSessionRequest} createSessionRequest 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        createSession(createSessionRequest: CreateSessionRequest, options?: RawAxiosRequestConfig): AxiosPromise<CreateSessionResponse> {
            return localVarFp.createSession(createSessionRequest, options).then((request) => request(axios, basePath));
        },
        /**
         * Returns sessions ordered by recency (newest first).
         * @summary List Sessions
         * @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}
         */
        listSessions(pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig): AxiosPromise<PaginatedSessionList> {
            return localVarFp.listSessions(pageLimit, pageOffset, options).then((request) => request(axios, basePath));
        },
        /**
         * Returns the full session detail including all conversation turns.
         * @summary Retrieve Session
         * @param {string} id Unique session identifier.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        retrieveSession(id: string, options?: RawAxiosRequestConfig): AxiosPromise<SessionDetail> {
            return localVarFp.retrieveSession(id, options).then((request) => request(axios, basePath));
        },
        /**
         * Append a user message to an existing session. The server will process it and produce assistant and tool turns asynchronously via the event stream.
         * @summary Send Session Message
         * @param {string} id Unique session identifier.
         * @param {SendMessageRequest} sendMessageRequest 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        sendSessionMessage(id: string, sendMessageRequest: SendMessageRequest, options?: RawAxiosRequestConfig): AxiosPromise<SendMessageResponse> {
            return localVarFp.sendSessionMessage(id, sendMessageRequest, options).then((request) => request(axios, basePath));
        },
        /**
         * Opens a server-sent event (SSE) stream for real-time session updates.  Each SSE frame includes a sequential numeric `id:` field that supports resumption via the `Last-Event-ID` request header.  The stream emits the following SSE event types:  - `event: content_delta` — data: `{\"delta\": \"...\"}` (incremental text chunk) - `event: assistant_turn` — data: `AssistantTurn` JSON object - `event: tool_turn` — data: `ToolTurn` JSON object - `event: done` — data: `{}` (stream complete) - `event: error` — data: `{\"message\": \"...\"}` (error occurred)  Each SSE frame has an `id:` line (sequential integer), an `event:` line (the event type), and a `data:` line (the JSON payload). 
         * @summary Stream Session Events
         * @param {string} id Unique session identifier.
         * @param {string} [lastEventID] SSE reconnection header. When provided, the server resumes the stream after the event with this ID. IDs are 0-based sequential integers assigned to each emitted SSE frame. 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        streamSessionEvents(id: string, lastEventID?: string, options?: RawAxiosRequestConfig): AxiosPromise<string> {
            return localVarFp.streamSessionEvents(id, lastEventID, options).then((request) => request(axios, basePath));
        },
    };
};

/**
 * SessionsApi - object-oriented interface
 */
export class SessionsApi extends BaseAPI {
    /**
     * Start a new interactive chat session. The initial user prompt is required; a model may optionally be specified.
     * @summary Create Session
     * @param {CreateSessionRequest} createSessionRequest 
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public createSession(createSessionRequest: CreateSessionRequest, options?: RawAxiosRequestConfig) {
        return SessionsApiFp(this.configuration).createSession(createSessionRequest, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Returns sessions ordered by recency (newest first).
     * @summary List Sessions
     * @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 listSessions(pageLimit?: number, pageOffset?: number, options?: RawAxiosRequestConfig) {
        return SessionsApiFp(this.configuration).listSessions(pageLimit, pageOffset, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Returns the full session detail including all conversation turns.
     * @summary Retrieve Session
     * @param {string} id Unique session identifier.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public retrieveSession(id: string, options?: RawAxiosRequestConfig) {
        return SessionsApiFp(this.configuration).retrieveSession(id, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Append a user message to an existing session. The server will process it and produce assistant and tool turns asynchronously via the event stream.
     * @summary Send Session Message
     * @param {string} id Unique session identifier.
     * @param {SendMessageRequest} sendMessageRequest 
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public sendSessionMessage(id: string, sendMessageRequest: SendMessageRequest, options?: RawAxiosRequestConfig) {
        return SessionsApiFp(this.configuration).sendSessionMessage(id, sendMessageRequest, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * Opens a server-sent event (SSE) stream for real-time session updates.  Each SSE frame includes a sequential numeric `id:` field that supports resumption via the `Last-Event-ID` request header.  The stream emits the following SSE event types:  - `event: content_delta` — data: `{\"delta\": \"...\"}` (incremental text chunk) - `event: assistant_turn` — data: `AssistantTurn` JSON object - `event: tool_turn` — data: `ToolTurn` JSON object - `event: done` — data: `{}` (stream complete) - `event: error` — data: `{\"message\": \"...\"}` (error occurred)  Each SSE frame has an `id:` line (sequential integer), an `event:` line (the event type), and a `data:` line (the JSON payload). 
     * @summary Stream Session Events
     * @param {string} id Unique session identifier.
     * @param {string} [lastEventID] SSE reconnection header. When provided, the server resumes the stream after the event with this ID. IDs are 0-based sequential integers assigned to each emitted SSE frame. 
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     */
    public streamSessionEvents(id: string, lastEventID?: string, options?: RawAxiosRequestConfig) {
        return SessionsApiFp(this.configuration).streamSessionEvents(id, lastEventID, options).then((request) => request(this.axios, this.basePath));
    }
}

