"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentUsage = exports.RunState = exports.Run_LabelsEntry = exports.Run = exports.runState_RunStatusToJSON = exports.runState_RunStatusFromJSON = exports.RunState_RunStatus = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const common_1 = require("../../../../../../yandex/cloud/ai/assistants/v1/common");
const timestamp_1 = require("../../../../../../google/protobuf/timestamp");
const common_2 = require("../../../../../../yandex/cloud/ai/common/common");
const message_1 = require("../../../../../../yandex/cloud/ai/assistants/v1/threads/message");
exports.protobufPackage = 'yandex.cloud.ai.assistants.v1.runs';
/** Enum representing the status of a run. */
var RunState_RunStatus;
(function (RunState_RunStatus) {
    /** RUN_STATUS_UNSPECIFIED - Default unspecified status. */
    RunState_RunStatus[RunState_RunStatus["RUN_STATUS_UNSPECIFIED"] = 0] = "RUN_STATUS_UNSPECIFIED";
    /** PENDING - Run has been created but has not started yet. */
    RunState_RunStatus[RunState_RunStatus["PENDING"] = 1] = "PENDING";
    /** IN_PROGRESS - Run is currently in progress. */
    RunState_RunStatus[RunState_RunStatus["IN_PROGRESS"] = 2] = "IN_PROGRESS";
    /** FAILED - Run has failed due to an error. */
    RunState_RunStatus[RunState_RunStatus["FAILED"] = 3] = "FAILED";
    /** COMPLETED - Run has completed successfully. */
    RunState_RunStatus[RunState_RunStatus["COMPLETED"] = 4] = "COMPLETED";
    /** TOOL_CALLS - The run is waiting for tool calls to be executed and their results to be submitted. */
    RunState_RunStatus[RunState_RunStatus["TOOL_CALLS"] = 5] = "TOOL_CALLS";
    RunState_RunStatus[RunState_RunStatus["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(RunState_RunStatus = exports.RunState_RunStatus || (exports.RunState_RunStatus = {}));
function runState_RunStatusFromJSON(object) {
    switch (object) {
        case 0:
        case 'RUN_STATUS_UNSPECIFIED':
            return RunState_RunStatus.RUN_STATUS_UNSPECIFIED;
        case 1:
        case 'PENDING':
            return RunState_RunStatus.PENDING;
        case 2:
        case 'IN_PROGRESS':
            return RunState_RunStatus.IN_PROGRESS;
        case 3:
        case 'FAILED':
            return RunState_RunStatus.FAILED;
        case 4:
        case 'COMPLETED':
            return RunState_RunStatus.COMPLETED;
        case 5:
        case 'TOOL_CALLS':
            return RunState_RunStatus.TOOL_CALLS;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return RunState_RunStatus.UNRECOGNIZED;
    }
}
exports.runState_RunStatusFromJSON = runState_RunStatusFromJSON;
function runState_RunStatusToJSON(object) {
    switch (object) {
        case RunState_RunStatus.RUN_STATUS_UNSPECIFIED:
            return 'RUN_STATUS_UNSPECIFIED';
        case RunState_RunStatus.PENDING:
            return 'PENDING';
        case RunState_RunStatus.IN_PROGRESS:
            return 'IN_PROGRESS';
        case RunState_RunStatus.FAILED:
            return 'FAILED';
        case RunState_RunStatus.COMPLETED:
            return 'COMPLETED';
        case RunState_RunStatus.TOOL_CALLS:
            return 'TOOL_CALLS';
        default:
            return 'UNKNOWN';
    }
}
exports.runState_RunStatusToJSON = runState_RunStatusToJSON;
const baseRun = { id: '', assistantId: '', threadId: '', createdBy: '' };
exports.Run = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.assistantId !== '') {
            writer.uint32(18).string(message.assistantId);
        }
        if (message.threadId !== '') {
            writer.uint32(26).string(message.threadId);
        }
        if (message.createdBy !== '') {
            writer.uint32(34).string(message.createdBy);
        }
        if (message.createdAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(42).fork()).ldelim();
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.Run_LabelsEntry.encode({ key: key, value }, writer.uint32(50).fork()).ldelim();
        });
        if (message.state !== undefined) {
            exports.RunState.encode(message.state, writer.uint32(58).fork()).ldelim();
        }
        if (message.usage !== undefined) {
            exports.ContentUsage.encode(message.usage, writer.uint32(66).fork()).ldelim();
        }
        if (message.customPromptTruncationOptions !== undefined) {
            common_1.PromptTruncationOptions.encode(message.customPromptTruncationOptions, writer.uint32(74).fork()).ldelim();
        }
        if (message.customCompletionOptions !== undefined) {
            common_1.CompletionOptions.encode(message.customCompletionOptions, writer.uint32(82).fork()).ldelim();
        }
        for (const v of message.tools) {
            common_1.Tool.encode(v, writer.uint32(90).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseRun);
        message.labels = {};
        message.tools = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.assistantId = reader.string();
                    break;
                case 3:
                    message.threadId = reader.string();
                    break;
                case 4:
                    message.createdBy = reader.string();
                    break;
                case 5:
                    message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 6:
                    const entry6 = exports.Run_LabelsEntry.decode(reader, reader.uint32());
                    if (entry6.value !== undefined) {
                        message.labels[entry6.key] = entry6.value;
                    }
                    break;
                case 7:
                    message.state = exports.RunState.decode(reader, reader.uint32());
                    break;
                case 8:
                    message.usage = exports.ContentUsage.decode(reader, reader.uint32());
                    break;
                case 9:
                    message.customPromptTruncationOptions = common_1.PromptTruncationOptions.decode(reader, reader.uint32());
                    break;
                case 10:
                    message.customCompletionOptions = common_1.CompletionOptions.decode(reader, reader.uint32());
                    break;
                case 11:
                    message.tools.push(common_1.Tool.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseRun);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.assistantId =
            object.assistantId !== undefined && object.assistantId !== null
                ? String(object.assistantId)
                : '';
        message.threadId =
            object.threadId !== undefined && object.threadId !== null
                ? String(object.threadId)
                : '';
        message.createdBy =
            object.createdBy !== undefined && object.createdBy !== null
                ? String(object.createdBy)
                : '';
        message.createdAt =
            object.createdAt !== undefined && object.createdAt !== null
                ? fromJsonTimestamp(object.createdAt)
                : undefined;
        message.labels = Object.entries((_a = object.labels) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.state =
            object.state !== undefined && object.state !== null
                ? exports.RunState.fromJSON(object.state)
                : undefined;
        message.usage =
            object.usage !== undefined && object.usage !== null
                ? exports.ContentUsage.fromJSON(object.usage)
                : undefined;
        message.customPromptTruncationOptions =
            object.customPromptTruncationOptions !== undefined &&
                object.customPromptTruncationOptions !== null
                ? common_1.PromptTruncationOptions.fromJSON(object.customPromptTruncationOptions)
                : undefined;
        message.customCompletionOptions =
            object.customCompletionOptions !== undefined && object.customCompletionOptions !== null
                ? common_1.CompletionOptions.fromJSON(object.customCompletionOptions)
                : undefined;
        message.tools = ((_b = object.tools) !== null && _b !== void 0 ? _b : []).map((e) => common_1.Tool.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.assistantId !== undefined && (obj.assistantId = message.assistantId);
        message.threadId !== undefined && (obj.threadId = message.threadId);
        message.createdBy !== undefined && (obj.createdBy = message.createdBy);
        message.createdAt !== undefined && (obj.createdAt = message.createdAt.toISOString());
        obj.labels = {};
        if (message.labels) {
            Object.entries(message.labels).forEach(([k, v]) => {
                obj.labels[k] = v;
            });
        }
        message.state !== undefined &&
            (obj.state = message.state ? exports.RunState.toJSON(message.state) : undefined);
        message.usage !== undefined &&
            (obj.usage = message.usage ? exports.ContentUsage.toJSON(message.usage) : undefined);
        message.customPromptTruncationOptions !== undefined &&
            (obj.customPromptTruncationOptions = message.customPromptTruncationOptions
                ? common_1.PromptTruncationOptions.toJSON(message.customPromptTruncationOptions)
                : undefined);
        message.customCompletionOptions !== undefined &&
            (obj.customCompletionOptions = message.customCompletionOptions
                ? common_1.CompletionOptions.toJSON(message.customCompletionOptions)
                : undefined);
        if (message.tools) {
            obj.tools = message.tools.map((e) => (e ? common_1.Tool.toJSON(e) : undefined));
        }
        else {
            obj.tools = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g;
        const message = Object.assign({}, baseRun);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.assistantId = (_b = object.assistantId) !== null && _b !== void 0 ? _b : '';
        message.threadId = (_c = object.threadId) !== null && _c !== void 0 ? _c : '';
        message.createdBy = (_d = object.createdBy) !== null && _d !== void 0 ? _d : '';
        message.createdAt = (_e = object.createdAt) !== null && _e !== void 0 ? _e : undefined;
        message.labels = Object.entries((_f = object.labels) !== null && _f !== void 0 ? _f : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.state =
            object.state !== undefined && object.state !== null
                ? exports.RunState.fromPartial(object.state)
                : undefined;
        message.usage =
            object.usage !== undefined && object.usage !== null
                ? exports.ContentUsage.fromPartial(object.usage)
                : undefined;
        message.customPromptTruncationOptions =
            object.customPromptTruncationOptions !== undefined &&
                object.customPromptTruncationOptions !== null
                ? common_1.PromptTruncationOptions.fromPartial(object.customPromptTruncationOptions)
                : undefined;
        message.customCompletionOptions =
            object.customCompletionOptions !== undefined && object.customCompletionOptions !== null
                ? common_1.CompletionOptions.fromPartial(object.customCompletionOptions)
                : undefined;
        message.tools = ((_g = object.tools) === null || _g === void 0 ? void 0 : _g.map((e) => common_1.Tool.fromPartial(e))) || [];
        return message;
    },
};
const baseRun_LabelsEntry = { key: '', value: '' };
exports.Run_LabelsEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.key !== '') {
            writer.uint32(10).string(message.key);
        }
        if (message.value !== '') {
            writer.uint32(18).string(message.value);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseRun_LabelsEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.key = reader.string();
                    break;
                case 2:
                    message.value = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseRun_LabelsEntry);
        message.key = object.key !== undefined && object.key !== null ? String(object.key) : '';
        message.value =
            object.value !== undefined && object.value !== null ? String(object.value) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.key !== undefined && (obj.key = message.key);
        message.value !== undefined && (obj.value = message.value);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseRun_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseRunState = { status: 0 };
exports.RunState = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.status !== 0) {
            writer.uint32(8).int32(message.status);
        }
        if (message.error !== undefined) {
            common_2.Error.encode(message.error, writer.uint32(18).fork()).ldelim();
        }
        if (message.completedMessage !== undefined) {
            message_1.Message.encode(message.completedMessage, writer.uint32(26).fork()).ldelim();
        }
        if (message.toolCallList !== undefined) {
            common_1.ToolCallList.encode(message.toolCallList, writer.uint32(34).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseRunState);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.status = reader.int32();
                    break;
                case 2:
                    message.error = common_2.Error.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.completedMessage = message_1.Message.decode(reader, reader.uint32());
                    break;
                case 4:
                    message.toolCallList = common_1.ToolCallList.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseRunState);
        message.status =
            object.status !== undefined && object.status !== null
                ? runState_RunStatusFromJSON(object.status)
                : 0;
        message.error =
            object.error !== undefined && object.error !== null
                ? common_2.Error.fromJSON(object.error)
                : undefined;
        message.completedMessage =
            object.completedMessage !== undefined && object.completedMessage !== null
                ? message_1.Message.fromJSON(object.completedMessage)
                : undefined;
        message.toolCallList =
            object.toolCallList !== undefined && object.toolCallList !== null
                ? common_1.ToolCallList.fromJSON(object.toolCallList)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.status !== undefined && (obj.status = runState_RunStatusToJSON(message.status));
        message.error !== undefined &&
            (obj.error = message.error ? common_2.Error.toJSON(message.error) : undefined);
        message.completedMessage !== undefined &&
            (obj.completedMessage = message.completedMessage
                ? message_1.Message.toJSON(message.completedMessage)
                : undefined);
        message.toolCallList !== undefined &&
            (obj.toolCallList = message.toolCallList
                ? common_1.ToolCallList.toJSON(message.toolCallList)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseRunState);
        message.status = (_a = object.status) !== null && _a !== void 0 ? _a : 0;
        message.error =
            object.error !== undefined && object.error !== null
                ? common_2.Error.fromPartial(object.error)
                : undefined;
        message.completedMessage =
            object.completedMessage !== undefined && object.completedMessage !== null
                ? message_1.Message.fromPartial(object.completedMessage)
                : undefined;
        message.toolCallList =
            object.toolCallList !== undefined && object.toolCallList !== null
                ? common_1.ToolCallList.fromPartial(object.toolCallList)
                : undefined;
        return message;
    },
};
const baseContentUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
exports.ContentUsage = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.promptTokens !== 0) {
            writer.uint32(8).int64(message.promptTokens);
        }
        if (message.completionTokens !== 0) {
            writer.uint32(16).int64(message.completionTokens);
        }
        if (message.totalTokens !== 0) {
            writer.uint32(24).int64(message.totalTokens);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseContentUsage);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.promptTokens = longToNumber(reader.int64());
                    break;
                case 2:
                    message.completionTokens = longToNumber(reader.int64());
                    break;
                case 3:
                    message.totalTokens = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseContentUsage);
        message.promptTokens =
            object.promptTokens !== undefined && object.promptTokens !== null
                ? Number(object.promptTokens)
                : 0;
        message.completionTokens =
            object.completionTokens !== undefined && object.completionTokens !== null
                ? Number(object.completionTokens)
                : 0;
        message.totalTokens =
            object.totalTokens !== undefined && object.totalTokens !== null
                ? Number(object.totalTokens)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.promptTokens !== undefined && (obj.promptTokens = Math.round(message.promptTokens));
        message.completionTokens !== undefined &&
            (obj.completionTokens = Math.round(message.completionTokens));
        message.totalTokens !== undefined && (obj.totalTokens = Math.round(message.totalTokens));
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseContentUsage);
        message.promptTokens = (_a = object.promptTokens) !== null && _a !== void 0 ? _a : 0;
        message.completionTokens = (_b = object.completionTokens) !== null && _b !== void 0 ? _b : 0;
        message.totalTokens = (_c = object.totalTokens) !== null && _c !== void 0 ? _c : 0;
        return message;
    },
};
var globalThis = (() => {
    if (typeof globalThis !== 'undefined')
        return globalThis;
    if (typeof self !== 'undefined')
        return self;
    if (typeof window !== 'undefined')
        return window;
    if (typeof global !== 'undefined')
        return global;
    throw 'Unable to locate global object';
})();
function toTimestamp(date) {
    const seconds = date.getTime() / 1000;
    const nanos = (date.getTime() % 1000) * 1000000;
    return { seconds, nanos };
}
function fromTimestamp(t) {
    let millis = t.seconds * 1000;
    millis += t.nanos / 1000000;
    return new Date(millis);
}
function fromJsonTimestamp(o) {
    if (o instanceof Date) {
        return o;
    }
    else if (typeof o === 'string') {
        return new Date(o);
    }
    else {
        return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
    }
}
function longToNumber(long) {
    if (long.gt(Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
    }
    return long.toNumber();
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
