"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageServiceClient = exports.MessageServiceService = exports.ListMessagesRequest = exports.GetMessageRequest = exports.CreateMessageRequest_LabelsEntry = exports.CreateMessageRequest = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const grpc_js_1 = require("@grpc/grpc-js");
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const message_1 = require("../../../../../../yandex/cloud/ai/assistants/v1/threads/message");
exports.protobufPackage = 'yandex.cloud.ai.assistants.v1.threads';
const baseCreateMessageRequest = { threadId: '' };
exports.CreateMessageRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.threadId !== '') {
            writer.uint32(10).string(message.threadId);
        }
        if (message.author !== undefined) {
            message_1.Author.encode(message.author, writer.uint32(18).fork()).ldelim();
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.CreateMessageRequest_LabelsEntry.encode({ key: key, value }, writer.uint32(26).fork()).ldelim();
        });
        if (message.content !== undefined) {
            message_1.MessageContent.encode(message.content, 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({}, baseCreateMessageRequest);
        message.labels = {};
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.threadId = reader.string();
                    break;
                case 2:
                    message.author = message_1.Author.decode(reader, reader.uint32());
                    break;
                case 3:
                    const entry3 = exports.CreateMessageRequest_LabelsEntry.decode(reader, reader.uint32());
                    if (entry3.value !== undefined) {
                        message.labels[entry3.key] = entry3.value;
                    }
                    break;
                case 4:
                    message.content = message_1.MessageContent.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseCreateMessageRequest);
        message.threadId =
            object.threadId !== undefined && object.threadId !== null
                ? String(object.threadId)
                : '';
        message.author =
            object.author !== undefined && object.author !== null
                ? message_1.Author.fromJSON(object.author)
                : undefined;
        message.labels = Object.entries((_a = object.labels) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.content =
            object.content !== undefined && object.content !== null
                ? message_1.MessageContent.fromJSON(object.content)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.threadId !== undefined && (obj.threadId = message.threadId);
        message.author !== undefined &&
            (obj.author = message.author ? message_1.Author.toJSON(message.author) : undefined);
        obj.labels = {};
        if (message.labels) {
            Object.entries(message.labels).forEach(([k, v]) => {
                obj.labels[k] = v;
            });
        }
        message.content !== undefined &&
            (obj.content = message.content ? message_1.MessageContent.toJSON(message.content) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseCreateMessageRequest);
        message.threadId = (_a = object.threadId) !== null && _a !== void 0 ? _a : '';
        message.author =
            object.author !== undefined && object.author !== null
                ? message_1.Author.fromPartial(object.author)
                : undefined;
        message.labels = Object.entries((_b = object.labels) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.content =
            object.content !== undefined && object.content !== null
                ? message_1.MessageContent.fromPartial(object.content)
                : undefined;
        return message;
    },
};
const baseCreateMessageRequest_LabelsEntry = { key: '', value: '' };
exports.CreateMessageRequest_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({}, baseCreateMessageRequest_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({}, baseCreateMessageRequest_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({}, baseCreateMessageRequest_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseGetMessageRequest = { threadId: '', messageId: '' };
exports.GetMessageRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.threadId !== '') {
            writer.uint32(10).string(message.threadId);
        }
        if (message.messageId !== '') {
            writer.uint32(18).string(message.messageId);
        }
        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({}, baseGetMessageRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.threadId = reader.string();
                    break;
                case 2:
                    message.messageId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetMessageRequest);
        message.threadId =
            object.threadId !== undefined && object.threadId !== null
                ? String(object.threadId)
                : '';
        message.messageId =
            object.messageId !== undefined && object.messageId !== null
                ? String(object.messageId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.threadId !== undefined && (obj.threadId = message.threadId);
        message.messageId !== undefined && (obj.messageId = message.messageId);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseGetMessageRequest);
        message.threadId = (_a = object.threadId) !== null && _a !== void 0 ? _a : '';
        message.messageId = (_b = object.messageId) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseListMessagesRequest = { threadId: '' };
exports.ListMessagesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.threadId !== '') {
            writer.uint32(10).string(message.threadId);
        }
        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({}, baseListMessagesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.threadId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListMessagesRequest);
        message.threadId =
            object.threadId !== undefined && object.threadId !== null
                ? String(object.threadId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.threadId !== undefined && (obj.threadId = message.threadId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseListMessagesRequest);
        message.threadId = (_a = object.threadId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
/** MessageService provides operations for managing messages. */
exports.MessageServiceService = {
    /** Create a new message. */
    create: {
        path: '/yandex.cloud.ai.assistants.v1.threads.MessageService/Create',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.CreateMessageRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.CreateMessageRequest.decode(value),
        responseSerialize: (value) => Buffer.from(message_1.Message.encode(value).finish()),
        responseDeserialize: (value) => message_1.Message.decode(value),
    },
    /** Retrieve details of a specific message by its ID. */
    get: {
        path: '/yandex.cloud.ai.assistants.v1.threads.MessageService/Get',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GetMessageRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GetMessageRequest.decode(value),
        responseSerialize: (value) => Buffer.from(message_1.Message.encode(value).finish()),
        responseDeserialize: (value) => message_1.Message.decode(value),
    },
    /**
     * List messages in a specific thread.
     * By default, messages are listed in reverse chronological order, i.e., from the newest to the oldest.
     */
    list: {
        path: '/yandex.cloud.ai.assistants.v1.threads.MessageService/List',
        requestStream: false,
        responseStream: true,
        requestSerialize: (value) => Buffer.from(exports.ListMessagesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListMessagesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(message_1.Message.encode(value).finish()),
        responseDeserialize: (value) => message_1.Message.decode(value),
    },
};
exports.MessageServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.MessageServiceService, 'yandex.cloud.ai.assistants.v1.threads.MessageService');
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
