/* tslint:disable */
/* eslint-disable */
/**
 * Vitron API
 * API documentation for Vitron backend
 *
 * The version of the OpenAPI document: v1
 * Contact: support@yourcompany.com
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import * as runtime from '../runtime';
import type {
  MarkMessagesAsReadResponse,
  MessageCreate,
  MessageList,
  PaginatedMessageList,
  ThreadCreate,
  ThreadDetail,
  ThreadLeaveResponse,
  ThreadList,
} from '../models';

export interface ApiChatV1ThreadsCreateCreateRequest {
    data: ThreadCreate;
}

export interface ApiChatV1ThreadsLeaveDeleteRequest {
    threadId: string;
}

export interface ApiChatV1ThreadsListListRequest {
    storeId?: string;
    userId?: string;
}

export interface ApiChatV1ThreadsMarkAsReadCreateRequest {
    threadId: string;
}

export interface ApiChatV1ThreadsMessagesListRequest {
    threadId: string;
    cursor?: string;
}

export interface ApiChatV1ThreadsMessagesSendCreateRequest {
    threadId: string;
    data: MessageCreate;
}

export interface ApiChatV1ThreadsReadRequest {
    threadId: string;
}

/**
 * 
 */
export class ChatApi extends runtime.BaseAPI {

    /**
     * Create a new thread or return existing one
     */
    async apiChatV1ThreadsCreateCreateRaw(requestParameters: ApiChatV1ThreadsCreateCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ThreadDetail>> {
        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiChatV1ThreadsCreateCreate.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/create/`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.data,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Create a new thread or return existing one
     */
    async apiChatV1ThreadsCreateCreate(requestParameters: ApiChatV1ThreadsCreateCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ThreadDetail> {
        const response = await this.apiChatV1ThreadsCreateCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Leave a thread
     */
    async apiChatV1ThreadsLeaveDeleteRaw(requestParameters: ApiChatV1ThreadsLeaveDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ThreadLeaveResponse>> {
        if (requestParameters.threadId === null || requestParameters.threadId === undefined) {
            throw new runtime.RequiredError('threadId','Required parameter requestParameters.threadId was null or undefined when calling apiChatV1ThreadsLeaveDelete.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/{thread_id}/leave/`.replace(`{${"thread_id"}}`, encodeURIComponent(String(requestParameters.threadId))),
            method: 'DELETE',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Leave a thread
     */
    async apiChatV1ThreadsLeaveDelete(requestParameters: ApiChatV1ThreadsLeaveDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ThreadLeaveResponse> {
        const response = await this.apiChatV1ThreadsLeaveDeleteRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * List user\'s threads
     */
    async apiChatV1ThreadsListRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<ThreadList>>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * List user\'s threads
     */
    async apiChatV1ThreadsList(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<ThreadList>> {
        const response = await this.apiChatV1ThreadsListRaw(initOverrides);
        return await response.value();
    }

    /**
     * List threads for a user or a store
     */
    async apiChatV1ThreadsListListRaw(requestParameters: ApiChatV1ThreadsListListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<ThreadList>>> {
        const queryParameters: any = {};

        if (requestParameters.storeId !== undefined) {
            queryParameters['store_id'] = requestParameters.storeId;
        }

        if (requestParameters.userId !== undefined) {
            queryParameters['user_id'] = requestParameters.userId;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/list/`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * List threads for a user or a store
     */
    async apiChatV1ThreadsListList(requestParameters: ApiChatV1ThreadsListListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<ThreadList>> {
        const response = await this.apiChatV1ThreadsListListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Mark thread as read (updates last_read_at)
     */
    async apiChatV1ThreadsMarkAsReadCreateRaw(requestParameters: ApiChatV1ThreadsMarkAsReadCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<MarkMessagesAsReadResponse>> {
        if (requestParameters.threadId === null || requestParameters.threadId === undefined) {
            throw new runtime.RequiredError('threadId','Required parameter requestParameters.threadId was null or undefined when calling apiChatV1ThreadsMarkAsReadCreate.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/{thread_id}/mark-as-read/`.replace(`{${"thread_id"}}`, encodeURIComponent(String(requestParameters.threadId))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Mark thread as read (updates last_read_at)
     */
    async apiChatV1ThreadsMarkAsReadCreate(requestParameters: ApiChatV1ThreadsMarkAsReadCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<MarkMessagesAsReadResponse> {
        const response = await this.apiChatV1ThreadsMarkAsReadCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get messages in a thread (cursor-based pagination)
     */
    async apiChatV1ThreadsMessagesListRaw(requestParameters: ApiChatV1ThreadsMessagesListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaginatedMessageList>> {
        if (requestParameters.threadId === null || requestParameters.threadId === undefined) {
            throw new runtime.RequiredError('threadId','Required parameter requestParameters.threadId was null or undefined when calling apiChatV1ThreadsMessagesList.');
        }

        const queryParameters: any = {};

        if (requestParameters.cursor !== undefined) {
            queryParameters['cursor'] = requestParameters.cursor;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/{thread_id}/messages/`.replace(`{${"thread_id"}}`, encodeURIComponent(String(requestParameters.threadId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Get messages in a thread (cursor-based pagination)
     */
    async apiChatV1ThreadsMessagesList(requestParameters: ApiChatV1ThreadsMessagesListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PaginatedMessageList> {
        const response = await this.apiChatV1ThreadsMessagesListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Send a message in a thread
     */
    async apiChatV1ThreadsMessagesSendCreateRaw(requestParameters: ApiChatV1ThreadsMessagesSendCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<MessageList>> {
        if (requestParameters.threadId === null || requestParameters.threadId === undefined) {
            throw new runtime.RequiredError('threadId','Required parameter requestParameters.threadId was null or undefined when calling apiChatV1ThreadsMessagesSendCreate.');
        }

        if (requestParameters.data === null || requestParameters.data === undefined) {
            throw new runtime.RequiredError('data','Required parameter requestParameters.data was null or undefined when calling apiChatV1ThreadsMessagesSendCreate.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/{thread_id}/messages/send/`.replace(`{${"thread_id"}}`, encodeURIComponent(String(requestParameters.threadId))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.data,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Send a message in a thread
     */
    async apiChatV1ThreadsMessagesSendCreate(requestParameters: ApiChatV1ThreadsMessagesSendCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<MessageList> {
        const response = await this.apiChatV1ThreadsMessagesSendCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get thread details
     */
    async apiChatV1ThreadsReadRaw(requestParameters: ApiChatV1ThreadsReadRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ThreadDetail>> {
        if (requestParameters.threadId === null || requestParameters.threadId === undefined) {
            throw new runtime.RequiredError('threadId','Required parameter requestParameters.threadId was null or undefined when calling apiChatV1ThreadsRead.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        const response = await this.request({
            path: `/api/chat/v1/threads/{thread_id}/`.replace(`{${"thread_id"}}`, encodeURIComponent(String(requestParameters.threadId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response);
    }

    /**
     * Get thread details
     */
    async apiChatV1ThreadsRead(requestParameters: ApiChatV1ThreadsReadRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ThreadDetail> {
        const response = await this.apiChatV1ThreadsReadRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
