"use strict";
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());
    });
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initAssistantSdk = exports.AssistantSdk = exports.AssistantWithSdk = void 0;
const assistant_service_1 = require("../../generated/yandex/cloud/ai/assistants/v1/assistant_service");
class AssistantWithSdk {
    constructor(assistantSdk, assistant) {
        this.assistantSdk = assistantSdk;
        this.assistant = assistant;
    }
    get data() {
        return this.assistant;
    }
    updateData(assistant) {
        this.assistant = assistant;
        return this;
    }
    delete(params, args) {
        const p = this.assistantSdk.delete(Object.assign(Object.assign({}, params), { assistantId: this.assistant.id }), args);
        return p;
    }
    update(params, args) {
        const p = this.assistantSdk.update(Object.assign(Object.assign({}, params), { assistantId: this.assistant.id }), args);
        return p.then(this.updateData.bind(this));
    }
}
exports.AssistantWithSdk = AssistantWithSdk;
class AssistantSdk {
    constructor(session, endpoint = AssistantSdk.ENDPOINT) {
        this.assistantClient = session.client(assistant_service_1.AssistantServiceClient, endpoint);
    }
    static _withSdk(assistantP) {
        function withSdk() {
            return __awaiter(this, void 0, void 0, function* () {
                const assistant = yield assistantP;
                return new AssistantWithSdk(this, assistant);
            });
        }
        return Object.assign(assistantP, { withSdk: withSdk.bind(this) });
    }
    create(params, args) {
        const { modelId } = params, restParams = __rest(params, ["modelId"]);
        const p = this.assistantClient.create(assistant_service_1.CreateAssistantRequest.fromPartial(Object.assign(Object.assign({}, restParams), { modelUri: `gpt://${params.folderId}/${modelId}` })), args);
        return AssistantSdk._withSdk.call(this, p);
    }
    get(params, args) {
        const p = this.assistantClient.get(assistant_service_1.GetAssistantRequest.fromPartial(params), args);
        return AssistantSdk._withSdk.call(this, p);
    }
    list(params, args) {
        const p = this.assistantClient.list(assistant_service_1.ListAssistantsRequest.fromPartial(params), args);
        return p;
    }
    delete(params, args) {
        const p = this.assistantClient.delete(assistant_service_1.DeleteAssistantRequest.fromPartial(params), args);
        return p;
    }
    listVersions(params, args) {
        const p = this.assistantClient.listVersions(assistant_service_1.ListAssistantVersionsRequest.fromPartial(params), args);
        return p;
    }
    update(params, args) {
        const p = this.assistantClient.update(assistant_service_1.UpdateAssistantRequest.fromPartial(params), args);
        return AssistantSdk._withSdk.call(this, p);
    }
}
exports.AssistantSdk = AssistantSdk;
AssistantSdk.ENDPOINT = 'assistant.api.cloud.yandex.net:443';
const initAssistantSdk = (session, endpoint = AssistantSdk.ENDPOINT) => {
    return new AssistantSdk(session, endpoint);
};
exports.initAssistantSdk = initAssistantSdk;
