"use strict";
// This file was auto-generated by Fern from our API Definition.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConversationsClient = void 0;
const BaseClient_1 = require("../../../../../../BaseClient");
const core = __importStar(require("../../../../../../core"));
const headers_1 = require("../../../../../../core/headers");
const environments = __importStar(require("../../../../../../environments"));
const handleNonStatusCodeError_1 = require("../../../../../../errors/handleNonStatusCodeError");
const errors = __importStar(require("../../../../../../errors/index"));
const serializers = __importStar(require("../../../../../../serialization/index"));
const ElevenLabs = __importStar(require("../../../../../index"));
const Client_1 = require("../resources/analysis/client/Client");
const Client_2 = require("../resources/audio/client/Client");
const Client_3 = require("../resources/feedback/client/Client");
const Client_4 = require("../resources/files/client/Client");
const Client_5 = require("../resources/messages/client/Client");
class ConversationsClient {
    constructor(options = {}) {
        this._options = (0, BaseClient_1.normalizeClientOptions)(options);
    }
    get audio() {
        var _a;
        return ((_a = this._audio) !== null && _a !== void 0 ? _a : (this._audio = new Client_2.AudioClient(this._options)));
    }
    get feedback() {
        var _a;
        return ((_a = this._feedback) !== null && _a !== void 0 ? _a : (this._feedback = new Client_3.FeedbackClient(this._options)));
    }
    get messages() {
        var _a;
        return ((_a = this._messages) !== null && _a !== void 0 ? _a : (this._messages = new Client_5.MessagesClient(this._options)));
    }
    get files() {
        var _a;
        return ((_a = this._files) !== null && _a !== void 0 ? _a : (this._files = new Client_4.FilesClient(this._options)));
    }
    get analysis() {
        var _a;
        return ((_a = this._analysis) !== null && _a !== void 0 ? _a : (this._analysis = new Client_1.AnalysisClient(this._options)));
    }
    /**
     * Get a signed url to start a conversation with an agent with an agent that requires authorization
     *
     * @param {ElevenLabs.conversationalAi.ConversationsGetSignedUrlRequest} request
     * @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.conversations.getSignedUrl({
     *         agentId: "21m00Tcm4TlvDq8ikWAM",
     *         includeConversationId: true,
     *         branchId: "branch_id",
     *         environment: "environment"
     *     })
     */
    getSignedUrl(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__getSignedUrl(request, requestOptions));
    }
    __getSignedUrl(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { agentId, includeConversationId, branchId, environment } = request;
            const _queryParams = {};
            _queryParams.agent_id = agentId;
            if (includeConversationId != null) {
                _queryParams.include_conversation_id = includeConversationId.toString();
            }
            if (branchId != null) {
                _queryParams.branch_id = branchId;
            }
            if (environment != null) {
                _queryParams.environment = environment;
            }
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, "v1/convai/conversation/get-signed-url"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.ConversationSignedUrlResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v1/convai/conversation/get-signed-url");
        });
    }
    /**
     * Get a WebRTC session token for real-time communication.
     *
     * @param {ElevenLabs.conversationalAi.ConversationsGetWebrtcTokenRequest} request
     * @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.conversations.getWebrtcToken({
     *         agentId: "21m00Tcm4TlvDq8ikWAM",
     *         participantName: "participant_name",
     *         branchId: "branch_id",
     *         environment: "environment"
     *     })
     */
    getWebrtcToken(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__getWebrtcToken(request, requestOptions));
    }
    __getWebrtcToken(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { agentId, participantName, branchId, environment } = request;
            const _queryParams = {};
            _queryParams.agent_id = agentId;
            if (participantName != null) {
                _queryParams.participant_name = participantName;
            }
            if (branchId != null) {
                _queryParams.branch_id = branchId;
            }
            if (environment != null) {
                _queryParams.environment = environment;
            }
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, "v1/convai/conversation/token"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.TokenResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v1/convai/conversation/token");
        });
    }
    /**
     * Get all conversations of agents that user owns. With option to restrict to a specific agent.
     *
     * @param {ElevenLabs.conversationalAi.ConversationsListRequest} request
     * @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.conversations.list({
     *         cursor: "cursor",
     *         agentId: "agent_id",
     *         callSuccessful: "success",
     *         callStartBeforeUnix: 1,
     *         callStartAfterUnix: 1,
     *         callDurationMinSecs: 1,
     *         callDurationMaxSecs: 1,
     *         ratingMax: 1,
     *         ratingMin: 1,
     *         hasFeedbackComment: true,
     *         userId: "user_id",
     *         pageSize: 1,
     *         summaryMode: "exclude",
     *         search: "search",
     *         conversationInitiationSource: "unknown",
     *         branchId: "branch_id"
     *     })
     */
    list(request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__list(request, requestOptions));
    }
    __list() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { cursor, agentId, callSuccessful, callStartBeforeUnix, callStartAfterUnix, callDurationMinSecs, callDurationMaxSecs, ratingMax, ratingMin, hasFeedbackComment, userId, evaluationParams, dataCollectionParams, toolNames, toolNamesSuccessful, toolNamesErrored, mainLanguages, pageSize, summaryMode, search, conversationInitiationSource, branchId, } = request;
            const _queryParams = {};
            if (cursor != null) {
                _queryParams.cursor = cursor;
            }
            if (agentId != null) {
                _queryParams.agent_id = agentId;
            }
            if (callSuccessful != null) {
                _queryParams.call_successful = serializers.EvaluationSuccessResult.jsonOrThrow(callSuccessful, {
                    unrecognizedObjectKeys: "strip",
                });
            }
            if (callStartBeforeUnix != null) {
                _queryParams.call_start_before_unix = callStartBeforeUnix.toString();
            }
            if (callStartAfterUnix != null) {
                _queryParams.call_start_after_unix = callStartAfterUnix.toString();
            }
            if (callDurationMinSecs != null) {
                _queryParams.call_duration_min_secs = callDurationMinSecs.toString();
            }
            if (callDurationMaxSecs != null) {
                _queryParams.call_duration_max_secs = callDurationMaxSecs.toString();
            }
            if (ratingMax != null) {
                _queryParams.rating_max = ratingMax.toString();
            }
            if (ratingMin != null) {
                _queryParams.rating_min = ratingMin.toString();
            }
            if (hasFeedbackComment != null) {
                _queryParams.has_feedback_comment = hasFeedbackComment.toString();
            }
            if (userId != null) {
                _queryParams.user_id = userId;
            }
            if (evaluationParams != null) {
                if (Array.isArray(evaluationParams)) {
                    _queryParams.evaluation_params = evaluationParams.map((item) => item);
                }
                else {
                    _queryParams.evaluation_params = evaluationParams;
                }
            }
            if (dataCollectionParams != null) {
                if (Array.isArray(dataCollectionParams)) {
                    _queryParams.data_collection_params = dataCollectionParams.map((item) => item);
                }
                else {
                    _queryParams.data_collection_params = dataCollectionParams;
                }
            }
            if (toolNames != null) {
                if (Array.isArray(toolNames)) {
                    _queryParams.tool_names = toolNames.map((item) => item);
                }
                else {
                    _queryParams.tool_names = toolNames;
                }
            }
            if (toolNamesSuccessful != null) {
                if (Array.isArray(toolNamesSuccessful)) {
                    _queryParams.tool_names_successful = toolNamesSuccessful.map((item) => item);
                }
                else {
                    _queryParams.tool_names_successful = toolNamesSuccessful;
                }
            }
            if (toolNamesErrored != null) {
                if (Array.isArray(toolNamesErrored)) {
                    _queryParams.tool_names_errored = toolNamesErrored.map((item) => item);
                }
                else {
                    _queryParams.tool_names_errored = toolNamesErrored;
                }
            }
            if (mainLanguages != null) {
                if (Array.isArray(mainLanguages)) {
                    _queryParams.main_languages = mainLanguages.map((item) => item);
                }
                else {
                    _queryParams.main_languages = mainLanguages;
                }
            }
            if (pageSize != null) {
                _queryParams.page_size = pageSize.toString();
            }
            if (summaryMode != null) {
                _queryParams.summary_mode = serializers.conversationalAi.ConversationsListRequestSummaryMode.jsonOrThrow(summaryMode, { unrecognizedObjectKeys: "strip" });
            }
            if (search != null) {
                _queryParams.search = search;
            }
            if (conversationInitiationSource != null) {
                _queryParams.conversation_initiation_source = serializers.ConversationInitiationSource.jsonOrThrow(conversationInitiationSource, { unrecognizedObjectKeys: "strip" });
            }
            if (branchId != null) {
                _queryParams.branch_id = branchId;
            }
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, "v1/convai/conversations"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.GetConversationsPageResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v1/convai/conversations");
        });
    }
    /**
     * Get the details of a particular conversation
     *
     * @param {string} conversation_id - The id of the conversation you're taking the action on.
     * @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.conversations.get("123")
     */
    get(conversation_id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__get(conversation_id, requestOptions));
    }
    __get(conversation_id, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, `v1/convai/conversations/${core.url.encodePathParam(conversation_id)}`),
                method: "GET",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.GetConversationResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v1/convai/conversations/{conversation_id}");
        });
    }
    /**
     * Delete a particular conversation
     *
     * @param {string} conversation_id - The id of the conversation you're taking the action on.
     * @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.conversations.delete("21m00Tcm4TlvDq8ikWAM")
     */
    delete(conversation_id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__delete(conversation_id, requestOptions));
    }
    __delete(conversation_id, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, `v1/convai/conversations/${core.url.encodePathParam(conversation_id)}`),
                method: "DELETE",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return { data: _response.body, rawResponse: _response.rawResponse };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "DELETE", "/v1/convai/conversations/{conversation_id}");
        });
    }
}
exports.ConversationsClient = ConversationsClient;
