"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.ElevenLabsClient = void 0;
const Client_1 = require("./api/resources/audioIsolation/client/Client");
const Client_2 = require("./api/resources/audioNative/client/Client");
const Client_3 = require("./api/resources/conversationalAi/client/Client");
const Client_4 = require("./api/resources/dubbing/client/Client");
const Client_5 = require("./api/resources/forcedAlignment/client/Client");
const Client_6 = require("./api/resources/history/client/Client");
const Client_7 = require("./api/resources/models/client/Client");
const Client_8 = require("./api/resources/music/client/Client");
const Client_9 = require("./api/resources/pronunciationDictionaries/client/Client");
const Client_10 = require("./api/resources/samples/client/Client");
const Client_11 = require("./api/resources/serviceAccounts/client/Client");
const Client_12 = require("./api/resources/speechToSpeech/client/Client");
const Client_13 = require("./api/resources/speechToText/client/Client");
const Client_14 = require("./api/resources/studio/client/Client");
const Client_15 = require("./api/resources/textToDialogue/client/Client");
const Client_16 = require("./api/resources/textToSoundEffects/client/Client");
const Client_17 = require("./api/resources/textToSpeech/client/Client");
const Client_18 = require("./api/resources/textToVoice/client/Client");
const Client_19 = require("./api/resources/tokens/client/Client");
const Client_20 = require("./api/resources/usage/client/Client");
const Client_21 = require("./api/resources/user/client/Client");
const Client_22 = require("./api/resources/voices/client/Client");
const Client_23 = require("./api/resources/webhooks/client/Client");
const Client_24 = require("./api/resources/workspace/client/Client");
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"));
class ElevenLabsClient {
    constructor(options = {}) {
        this._options = (0, BaseClient_1.normalizeClientOptions)(options);
    }
    get history() {
        var _a;
        return ((_a = this._history) !== null && _a !== void 0 ? _a : (this._history = new Client_6.HistoryClient(this._options)));
    }
    get textToSoundEffects() {
        var _a;
        return ((_a = this._textToSoundEffects) !== null && _a !== void 0 ? _a : (this._textToSoundEffects = new Client_16.TextToSoundEffectsClient(this._options)));
    }
    get audioIsolation() {
        var _a;
        return ((_a = this._audioIsolation) !== null && _a !== void 0 ? _a : (this._audioIsolation = new Client_1.AudioIsolationClient(this._options)));
    }
    get samples() {
        var _a;
        return ((_a = this._samples) !== null && _a !== void 0 ? _a : (this._samples = new Client_10.SamplesClient(this._options)));
    }
    get textToSpeech() {
        var _a;
        return ((_a = this._textToSpeech) !== null && _a !== void 0 ? _a : (this._textToSpeech = new Client_17.TextToSpeechClient(this._options)));
    }
    get textToDialogue() {
        var _a;
        return ((_a = this._textToDialogue) !== null && _a !== void 0 ? _a : (this._textToDialogue = new Client_15.TextToDialogueClient(this._options)));
    }
    get speechToSpeech() {
        var _a;
        return ((_a = this._speechToSpeech) !== null && _a !== void 0 ? _a : (this._speechToSpeech = new Client_12.SpeechToSpeechClient(this._options)));
    }
    get textToVoice() {
        var _a;
        return ((_a = this._textToVoice) !== null && _a !== void 0 ? _a : (this._textToVoice = new Client_18.TextToVoiceClient(this._options)));
    }
    get user() {
        var _a;
        return ((_a = this._user) !== null && _a !== void 0 ? _a : (this._user = new Client_21.UserClient(this._options)));
    }
    get voices() {
        var _a;
        return ((_a = this._voices) !== null && _a !== void 0 ? _a : (this._voices = new Client_22.VoicesClient(this._options)));
    }
    get studio() {
        var _a;
        return ((_a = this._studio) !== null && _a !== void 0 ? _a : (this._studio = new Client_14.StudioClient(this._options)));
    }
    get dubbing() {
        var _a;
        return ((_a = this._dubbing) !== null && _a !== void 0 ? _a : (this._dubbing = new Client_4.DubbingClient(this._options)));
    }
    get models() {
        var _a;
        return ((_a = this._models) !== null && _a !== void 0 ? _a : (this._models = new Client_7.ModelsClient(this._options)));
    }
    get audioNative() {
        var _a;
        return ((_a = this._audioNative) !== null && _a !== void 0 ? _a : (this._audioNative = new Client_2.AudioNativeClient(this._options)));
    }
    get usage() {
        var _a;
        return ((_a = this._usage) !== null && _a !== void 0 ? _a : (this._usage = new Client_20.UsageClient(this._options)));
    }
    get pronunciationDictionaries() {
        var _a;
        return ((_a = this._pronunciationDictionaries) !== null && _a !== void 0 ? _a : (this._pronunciationDictionaries = new Client_9.PronunciationDictionariesClient(this._options)));
    }
    get serviceAccounts() {
        var _a;
        return ((_a = this._serviceAccounts) !== null && _a !== void 0 ? _a : (this._serviceAccounts = new Client_11.ServiceAccountsClient(this._options)));
    }
    get webhooks() {
        var _a;
        return ((_a = this._webhooks) !== null && _a !== void 0 ? _a : (this._webhooks = new Client_23.WebhooksClient(this._options)));
    }
    get speechToText() {
        var _a;
        return ((_a = this._speechToText) !== null && _a !== void 0 ? _a : (this._speechToText = new Client_13.SpeechToTextClient(this._options)));
    }
    get forcedAlignment() {
        var _a;
        return ((_a = this._forcedAlignment) !== null && _a !== void 0 ? _a : (this._forcedAlignment = new Client_5.ForcedAlignmentClient(this._options)));
    }
    get conversationalAi() {
        var _a;
        return ((_a = this._conversationalAi) !== null && _a !== void 0 ? _a : (this._conversationalAi = new Client_3.ConversationalAiClient(this._options)));
    }
    get music() {
        var _a;
        return ((_a = this._music) !== null && _a !== void 0 ? _a : (this._music = new Client_8.MusicClient(this._options)));
    }
    get tokens() {
        var _a;
        return ((_a = this._tokens) !== null && _a !== void 0 ? _a : (this._tokens = new Client_19.TokensClient(this._options)));
    }
    get workspace() {
        var _a;
        return ((_a = this._workspace) !== null && _a !== void 0 ? _a : (this._workspace = new Client_24.WorkspaceClient(this._options)));
    }
    /**
     * @param {string} agent_id
     * @param {string} branch_id
     * @param {ElevenLabsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.deleteV1ConvaiAgentsAgentIdBranchesBranchId("agent_id", "branch_id")
     */
    deleteV1ConvaiAgentsAgentIdBranchesBranchId(agent_id, branch_id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__deleteV1ConvaiAgentsAgentIdBranchesBranchId(agent_id, branch_id, requestOptions));
    }
    __deleteV1ConvaiAgentsAgentIdBranchesBranchId(agent_id, branch_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/agents/${core.url.encodePathParam(agent_id)}/branches/${core.url.encodePathParam(branch_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: undefined, rawResponse: _response.rawResponse };
            }
            if (_response.error.reason === "status-code") {
                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/agents/{agent_id}/branches/{branch_id}");
        });
    }
    /**
     * Add a generated voice to the voice library.
     *
     * @param {ElevenLabsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.saveAVoicePreview()
     */
    saveAVoicePreview(requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__saveAVoicePreview(requestOptions));
    }
    __saveAVoicePreview(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/text-to-voice/create-voice-from-preview"),
                method: "POST",
                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: undefined, rawResponse: _response.rawResponse };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.ElevenLabsError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/v1/text-to-voice/create-voice-from-preview");
        });
    }
}
exports.ElevenLabsClient = ElevenLabsClient;
