"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChunkContent = exports.FileChunk = exports.Source = exports.Citation = exports.Author = exports.ContentPart = exports.Text = exports.MessageData_LabelsEntry = exports.MessageData = exports.MessageContent = exports.Message_LabelsEntry = exports.Message = exports.message_MessageStatusToJSON = exports.message_MessageStatusFromJSON = exports.Message_MessageStatus = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const search_index_1 = require("../../../../../../yandex/cloud/ai/assistants/v1/searchindex/search_index");
const file_1 = require("../../../../../../yandex/cloud/ai/files/v1/file");
const timestamp_1 = require("../../../../../../google/protobuf/timestamp");
exports.protobufPackage = 'yandex.cloud.ai.assistants.v1.threads';
/** Enum representing the status of a message. */
var Message_MessageStatus;
(function (Message_MessageStatus) {
    /** MESSAGE_STATUS_UNSPECIFIED - Unspecified message status. */
    Message_MessageStatus[Message_MessageStatus["MESSAGE_STATUS_UNSPECIFIED"] = 0] = "MESSAGE_STATUS_UNSPECIFIED";
    /** COMPLETED - Message was successfully created by a user or generated by an assistant. */
    Message_MessageStatus[Message_MessageStatus["COMPLETED"] = 1] = "COMPLETED";
    /** TRUNCATED - Message generation was truncated due to reaching the maximum allowed number of tokens. */
    Message_MessageStatus[Message_MessageStatus["TRUNCATED"] = 2] = "TRUNCATED";
    /** FILTERED_CONTENT - Message generation was stopped because potentially sensitive content was detected either in the prompt or in the generated response. */
    Message_MessageStatus[Message_MessageStatus["FILTERED_CONTENT"] = 3] = "FILTERED_CONTENT";
    Message_MessageStatus[Message_MessageStatus["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(Message_MessageStatus = exports.Message_MessageStatus || (exports.Message_MessageStatus = {}));
function message_MessageStatusFromJSON(object) {
    switch (object) {
        case 0:
        case 'MESSAGE_STATUS_UNSPECIFIED':
            return Message_MessageStatus.MESSAGE_STATUS_UNSPECIFIED;
        case 1:
        case 'COMPLETED':
            return Message_MessageStatus.COMPLETED;
        case 2:
        case 'TRUNCATED':
            return Message_MessageStatus.TRUNCATED;
        case 3:
        case 'FILTERED_CONTENT':
            return Message_MessageStatus.FILTERED_CONTENT;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return Message_MessageStatus.UNRECOGNIZED;
    }
}
exports.message_MessageStatusFromJSON = message_MessageStatusFromJSON;
function message_MessageStatusToJSON(object) {
    switch (object) {
        case Message_MessageStatus.MESSAGE_STATUS_UNSPECIFIED:
            return 'MESSAGE_STATUS_UNSPECIFIED';
        case Message_MessageStatus.COMPLETED:
            return 'COMPLETED';
        case Message_MessageStatus.TRUNCATED:
            return 'TRUNCATED';
        case Message_MessageStatus.FILTERED_CONTENT:
            return 'FILTERED_CONTENT';
        default:
            return 'UNKNOWN';
    }
}
exports.message_MessageStatusToJSON = message_MessageStatusToJSON;
const baseMessage = { id: '', threadId: '', createdBy: '', status: 0 };
exports.Message = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.threadId !== '') {
            writer.uint32(18).string(message.threadId);
        }
        if (message.createdBy !== '') {
            writer.uint32(26).string(message.createdBy);
        }
        if (message.createdAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(34).fork()).ldelim();
        }
        if (message.author !== undefined) {
            exports.Author.encode(message.author, writer.uint32(42).fork()).ldelim();
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.Message_LabelsEntry.encode({ key: key, value }, writer.uint32(50).fork()).ldelim();
        });
        if (message.content !== undefined) {
            exports.MessageContent.encode(message.content, writer.uint32(58).fork()).ldelim();
        }
        if (message.status !== 0) {
            writer.uint32(64).int32(message.status);
        }
        for (const v of message.citations) {
            exports.Citation.encode(v, writer.uint32(74).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({}, baseMessage);
        message.labels = {};
        message.citations = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.threadId = reader.string();
                    break;
                case 3:
                    message.createdBy = reader.string();
                    break;
                case 4:
                    message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 5:
                    message.author = exports.Author.decode(reader, reader.uint32());
                    break;
                case 6:
                    const entry6 = exports.Message_LabelsEntry.decode(reader, reader.uint32());
                    if (entry6.value !== undefined) {
                        message.labels[entry6.key] = entry6.value;
                    }
                    break;
                case 7:
                    message.content = exports.MessageContent.decode(reader, reader.uint32());
                    break;
                case 8:
                    message.status = reader.int32();
                    break;
                case 9:
                    message.citations.push(exports.Citation.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseMessage);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        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.author =
            object.author !== undefined && object.author !== null
                ? exports.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
                ? exports.MessageContent.fromJSON(object.content)
                : undefined;
        message.status =
            object.status !== undefined && object.status !== null
                ? message_MessageStatusFromJSON(object.status)
                : 0;
        message.citations = ((_b = object.citations) !== null && _b !== void 0 ? _b : []).map((e) => exports.Citation.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.threadId !== undefined && (obj.threadId = message.threadId);
        message.createdBy !== undefined && (obj.createdBy = message.createdBy);
        message.createdAt !== undefined && (obj.createdAt = message.createdAt.toISOString());
        message.author !== undefined &&
            (obj.author = message.author ? exports.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 ? exports.MessageContent.toJSON(message.content) : undefined);
        message.status !== undefined && (obj.status = message_MessageStatusToJSON(message.status));
        if (message.citations) {
            obj.citations = message.citations.map((e) => (e ? exports.Citation.toJSON(e) : undefined));
        }
        else {
            obj.citations = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g;
        const message = Object.assign({}, baseMessage);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.threadId = (_b = object.threadId) !== null && _b !== void 0 ? _b : '';
        message.createdBy = (_c = object.createdBy) !== null && _c !== void 0 ? _c : '';
        message.createdAt = (_d = object.createdAt) !== null && _d !== void 0 ? _d : undefined;
        message.author =
            object.author !== undefined && object.author !== null
                ? exports.Author.fromPartial(object.author)
                : undefined;
        message.labels = Object.entries((_e = object.labels) !== null && _e !== void 0 ? _e : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.content =
            object.content !== undefined && object.content !== null
                ? exports.MessageContent.fromPartial(object.content)
                : undefined;
        message.status = (_f = object.status) !== null && _f !== void 0 ? _f : 0;
        message.citations = ((_g = object.citations) === null || _g === void 0 ? void 0 : _g.map((e) => exports.Citation.fromPartial(e))) || [];
        return message;
    },
};
const baseMessage_LabelsEntry = { key: '', value: '' };
exports.Message_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({}, baseMessage_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({}, baseMessage_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({}, baseMessage_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseMessageContent = {};
exports.MessageContent = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.content) {
            exports.ContentPart.encode(v, writer.uint32(10).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({}, baseMessageContent);
        message.content = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.content.push(exports.ContentPart.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseMessageContent);
        message.content = ((_a = object.content) !== null && _a !== void 0 ? _a : []).map((e) => exports.ContentPart.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.content) {
            obj.content = message.content.map((e) => (e ? exports.ContentPart.toJSON(e) : undefined));
        }
        else {
            obj.content = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseMessageContent);
        message.content = ((_a = object.content) === null || _a === void 0 ? void 0 : _a.map((e) => exports.ContentPart.fromPartial(e))) || [];
        return message;
    },
};
const baseMessageData = {};
exports.MessageData = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.author !== undefined) {
            exports.Author.encode(message.author, writer.uint32(10).fork()).ldelim();
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.MessageData_LabelsEntry.encode({ key: key, value }, writer.uint32(18).fork()).ldelim();
        });
        if (message.content !== undefined) {
            exports.MessageContent.encode(message.content, writer.uint32(26).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({}, baseMessageData);
        message.labels = {};
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.author = exports.Author.decode(reader, reader.uint32());
                    break;
                case 2:
                    const entry2 = exports.MessageData_LabelsEntry.decode(reader, reader.uint32());
                    if (entry2.value !== undefined) {
                        message.labels[entry2.key] = entry2.value;
                    }
                    break;
                case 3:
                    message.content = exports.MessageContent.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseMessageData);
        message.author =
            object.author !== undefined && object.author !== null
                ? exports.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
                ? exports.MessageContent.fromJSON(object.content)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.author !== undefined &&
            (obj.author = message.author ? exports.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 ? exports.MessageContent.toJSON(message.content) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseMessageData);
        message.author =
            object.author !== undefined && object.author !== null
                ? exports.Author.fromPartial(object.author)
                : undefined;
        message.labels = Object.entries((_a = object.labels) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.content =
            object.content !== undefined && object.content !== null
                ? exports.MessageContent.fromPartial(object.content)
                : undefined;
        return message;
    },
};
const baseMessageData_LabelsEntry = { key: '', value: '' };
exports.MessageData_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({}, baseMessageData_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({}, baseMessageData_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({}, baseMessageData_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseText = { content: '' };
exports.Text = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.content !== '') {
            writer.uint32(10).string(message.content);
        }
        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({}, baseText);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.content = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseText);
        message.content =
            object.content !== undefined && object.content !== null ? String(object.content) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.content !== undefined && (obj.content = message.content);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseText);
        message.content = (_a = object.content) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseContentPart = {};
exports.ContentPart = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.text !== undefined) {
            exports.Text.encode(message.text, writer.uint32(10).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({}, baseContentPart);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.text = exports.Text.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseContentPart);
        message.text =
            object.text !== undefined && object.text !== null
                ? exports.Text.fromJSON(object.text)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.text !== undefined &&
            (obj.text = message.text ? exports.Text.toJSON(message.text) : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseContentPart);
        message.text =
            object.text !== undefined && object.text !== null
                ? exports.Text.fromPartial(object.text)
                : undefined;
        return message;
    },
};
const baseAuthor = { id: '', role: '' };
exports.Author = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.role !== '') {
            writer.uint32(18).string(message.role);
        }
        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({}, baseAuthor);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.role = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAuthor);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.role = object.role !== undefined && object.role !== null ? String(object.role) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.role !== undefined && (obj.role = message.role);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseAuthor);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.role = (_b = object.role) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseCitation = {};
exports.Citation = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.sources) {
            exports.Source.encode(v, 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({}, baseCitation);
        message.sources = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 4:
                    message.sources.push(exports.Source.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseCitation);
        message.sources = ((_a = object.sources) !== null && _a !== void 0 ? _a : []).map((e) => exports.Source.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.sources) {
            obj.sources = message.sources.map((e) => (e ? exports.Source.toJSON(e) : undefined));
        }
        else {
            obj.sources = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseCitation);
        message.sources = ((_a = object.sources) === null || _a === void 0 ? void 0 : _a.map((e) => exports.Source.fromPartial(e))) || [];
        return message;
    },
};
const baseSource = {};
exports.Source = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.chunk !== undefined) {
            exports.FileChunk.encode(message.chunk, writer.uint32(10).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({}, baseSource);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.chunk = exports.FileChunk.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseSource);
        message.chunk =
            object.chunk !== undefined && object.chunk !== null
                ? exports.FileChunk.fromJSON(object.chunk)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.chunk !== undefined &&
            (obj.chunk = message.chunk ? exports.FileChunk.toJSON(message.chunk) : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseSource);
        message.chunk =
            object.chunk !== undefined && object.chunk !== null
                ? exports.FileChunk.fromPartial(object.chunk)
                : undefined;
        return message;
    },
};
const baseFileChunk = {};
exports.FileChunk = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.searchIndex !== undefined) {
            search_index_1.SearchIndex.encode(message.searchIndex, writer.uint32(10).fork()).ldelim();
        }
        if (message.sourceFile !== undefined) {
            file_1.File.encode(message.sourceFile, writer.uint32(18).fork()).ldelim();
        }
        if (message.content !== undefined) {
            exports.ChunkContent.encode(message.content, writer.uint32(26).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({}, baseFileChunk);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.searchIndex = search_index_1.SearchIndex.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.sourceFile = file_1.File.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.content = exports.ChunkContent.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseFileChunk);
        message.searchIndex =
            object.searchIndex !== undefined && object.searchIndex !== null
                ? search_index_1.SearchIndex.fromJSON(object.searchIndex)
                : undefined;
        message.sourceFile =
            object.sourceFile !== undefined && object.sourceFile !== null
                ? file_1.File.fromJSON(object.sourceFile)
                : undefined;
        message.content =
            object.content !== undefined && object.content !== null
                ? exports.ChunkContent.fromJSON(object.content)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.searchIndex !== undefined &&
            (obj.searchIndex = message.searchIndex
                ? search_index_1.SearchIndex.toJSON(message.searchIndex)
                : undefined);
        message.sourceFile !== undefined &&
            (obj.sourceFile = message.sourceFile ? file_1.File.toJSON(message.sourceFile) : undefined);
        message.content !== undefined &&
            (obj.content = message.content ? exports.ChunkContent.toJSON(message.content) : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseFileChunk);
        message.searchIndex =
            object.searchIndex !== undefined && object.searchIndex !== null
                ? search_index_1.SearchIndex.fromPartial(object.searchIndex)
                : undefined;
        message.sourceFile =
            object.sourceFile !== undefined && object.sourceFile !== null
                ? file_1.File.fromPartial(object.sourceFile)
                : undefined;
        message.content =
            object.content !== undefined && object.content !== null
                ? exports.ChunkContent.fromPartial(object.content)
                : undefined;
        return message;
    },
};
const baseChunkContent = {};
exports.ChunkContent = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.content) {
            exports.ContentPart.encode(v, writer.uint32(10).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({}, baseChunkContent);
        message.content = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.content.push(exports.ContentPart.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseChunkContent);
        message.content = ((_a = object.content) !== null && _a !== void 0 ? _a : []).map((e) => exports.ContentPart.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.content) {
            obj.content = message.content.map((e) => (e ? exports.ContentPart.toJSON(e) : undefined));
        }
        else {
            obj.content = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseChunkContent);
        message.content = ((_a = object.content) === null || _a === void 0 ? void 0 : _a.map((e) => exports.ContentPart.fromPartial(e))) || [];
        return message;
    },
};
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));
    }
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
