"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableCell = exports.Table = exports.TextSegments = exports.Word = exports.Line = exports.Block_DetectedLanguage = exports.Block = exports.Entity = exports.TextAnnotation = exports.Vertex = exports.Polygon = exports.angleToJSON = exports.angleFromJSON = exports.Angle = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
exports.protobufPackage = 'yandex.cloud.ai.ocr.v1';
var Angle;
(function (Angle) {
    Angle[Angle["ANGLE_UNSPECIFIED"] = 0] = "ANGLE_UNSPECIFIED";
    Angle[Angle["ANGLE_0"] = 1] = "ANGLE_0";
    Angle[Angle["ANGLE_90"] = 2] = "ANGLE_90";
    Angle[Angle["ANGLE_180"] = 3] = "ANGLE_180";
    Angle[Angle["ANGLE_270"] = 4] = "ANGLE_270";
    Angle[Angle["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(Angle = exports.Angle || (exports.Angle = {}));
function angleFromJSON(object) {
    switch (object) {
        case 0:
        case 'ANGLE_UNSPECIFIED':
            return Angle.ANGLE_UNSPECIFIED;
        case 1:
        case 'ANGLE_0':
            return Angle.ANGLE_0;
        case 2:
        case 'ANGLE_90':
            return Angle.ANGLE_90;
        case 3:
        case 'ANGLE_180':
            return Angle.ANGLE_180;
        case 4:
        case 'ANGLE_270':
            return Angle.ANGLE_270;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return Angle.UNRECOGNIZED;
    }
}
exports.angleFromJSON = angleFromJSON;
function angleToJSON(object) {
    switch (object) {
        case Angle.ANGLE_UNSPECIFIED:
            return 'ANGLE_UNSPECIFIED';
        case Angle.ANGLE_0:
            return 'ANGLE_0';
        case Angle.ANGLE_90:
            return 'ANGLE_90';
        case Angle.ANGLE_180:
            return 'ANGLE_180';
        case Angle.ANGLE_270:
            return 'ANGLE_270';
        default:
            return 'UNKNOWN';
    }
}
exports.angleToJSON = angleToJSON;
const basePolygon = {};
exports.Polygon = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.vertices) {
            exports.Vertex.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({}, basePolygon);
        message.vertices = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.vertices.push(exports.Vertex.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, basePolygon);
        message.vertices = ((_a = object.vertices) !== null && _a !== void 0 ? _a : []).map((e) => exports.Vertex.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.vertices) {
            obj.vertices = message.vertices.map((e) => (e ? exports.Vertex.toJSON(e) : undefined));
        }
        else {
            obj.vertices = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, basePolygon);
        message.vertices = ((_a = object.vertices) === null || _a === void 0 ? void 0 : _a.map((e) => exports.Vertex.fromPartial(e))) || [];
        return message;
    },
};
const baseVertex = { x: 0, y: 0 };
exports.Vertex = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.x !== 0) {
            writer.uint32(8).int64(message.x);
        }
        if (message.y !== 0) {
            writer.uint32(16).int64(message.y);
        }
        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({}, baseVertex);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.x = longToNumber(reader.int64());
                    break;
                case 2:
                    message.y = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseVertex);
        message.x = object.x !== undefined && object.x !== null ? Number(object.x) : 0;
        message.y = object.y !== undefined && object.y !== null ? Number(object.y) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.x !== undefined && (obj.x = Math.round(message.x));
        message.y !== undefined && (obj.y = Math.round(message.y));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseVertex);
        message.x = (_a = object.x) !== null && _a !== void 0 ? _a : 0;
        message.y = (_b = object.y) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseTextAnnotation = { width: 0, height: 0, fullText: '', rotate: 0 };
exports.TextAnnotation = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.width !== 0) {
            writer.uint32(8).int64(message.width);
        }
        if (message.height !== 0) {
            writer.uint32(16).int64(message.height);
        }
        for (const v of message.blocks) {
            exports.Block.encode(v, writer.uint32(26).fork()).ldelim();
        }
        for (const v of message.entities) {
            exports.Entity.encode(v, writer.uint32(34).fork()).ldelim();
        }
        for (const v of message.tables) {
            exports.Table.encode(v, writer.uint32(42).fork()).ldelim();
        }
        if (message.fullText !== '') {
            writer.uint32(50).string(message.fullText);
        }
        if (message.rotate !== 0) {
            writer.uint32(56).int32(message.rotate);
        }
        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({}, baseTextAnnotation);
        message.blocks = [];
        message.entities = [];
        message.tables = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.width = longToNumber(reader.int64());
                    break;
                case 2:
                    message.height = longToNumber(reader.int64());
                    break;
                case 3:
                    message.blocks.push(exports.Block.decode(reader, reader.uint32()));
                    break;
                case 4:
                    message.entities.push(exports.Entity.decode(reader, reader.uint32()));
                    break;
                case 5:
                    message.tables.push(exports.Table.decode(reader, reader.uint32()));
                    break;
                case 6:
                    message.fullText = reader.string();
                    break;
                case 7:
                    message.rotate = reader.int32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseTextAnnotation);
        message.width =
            object.width !== undefined && object.width !== null ? Number(object.width) : 0;
        message.height =
            object.height !== undefined && object.height !== null ? Number(object.height) : 0;
        message.blocks = ((_a = object.blocks) !== null && _a !== void 0 ? _a : []).map((e) => exports.Block.fromJSON(e));
        message.entities = ((_b = object.entities) !== null && _b !== void 0 ? _b : []).map((e) => exports.Entity.fromJSON(e));
        message.tables = ((_c = object.tables) !== null && _c !== void 0 ? _c : []).map((e) => exports.Table.fromJSON(e));
        message.fullText =
            object.fullText !== undefined && object.fullText !== null
                ? String(object.fullText)
                : '';
        message.rotate =
            object.rotate !== undefined && object.rotate !== null
                ? angleFromJSON(object.rotate)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.width !== undefined && (obj.width = Math.round(message.width));
        message.height !== undefined && (obj.height = Math.round(message.height));
        if (message.blocks) {
            obj.blocks = message.blocks.map((e) => (e ? exports.Block.toJSON(e) : undefined));
        }
        else {
            obj.blocks = [];
        }
        if (message.entities) {
            obj.entities = message.entities.map((e) => (e ? exports.Entity.toJSON(e) : undefined));
        }
        else {
            obj.entities = [];
        }
        if (message.tables) {
            obj.tables = message.tables.map((e) => (e ? exports.Table.toJSON(e) : undefined));
        }
        else {
            obj.tables = [];
        }
        message.fullText !== undefined && (obj.fullText = message.fullText);
        message.rotate !== undefined && (obj.rotate = angleToJSON(message.rotate));
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g;
        const message = Object.assign({}, baseTextAnnotation);
        message.width = (_a = object.width) !== null && _a !== void 0 ? _a : 0;
        message.height = (_b = object.height) !== null && _b !== void 0 ? _b : 0;
        message.blocks = ((_c = object.blocks) === null || _c === void 0 ? void 0 : _c.map((e) => exports.Block.fromPartial(e))) || [];
        message.entities = ((_d = object.entities) === null || _d === void 0 ? void 0 : _d.map((e) => exports.Entity.fromPartial(e))) || [];
        message.tables = ((_e = object.tables) === null || _e === void 0 ? void 0 : _e.map((e) => exports.Table.fromPartial(e))) || [];
        message.fullText = (_f = object.fullText) !== null && _f !== void 0 ? _f : '';
        message.rotate = (_g = object.rotate) !== null && _g !== void 0 ? _g : 0;
        return message;
    },
};
const baseEntity = { name: '', text: '' };
exports.Entity = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.name !== '') {
            writer.uint32(10).string(message.name);
        }
        if (message.text !== '') {
            writer.uint32(18).string(message.text);
        }
        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({}, baseEntity);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.name = reader.string();
                    break;
                case 2:
                    message.text = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseEntity);
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.text = object.text !== undefined && object.text !== null ? String(object.text) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.name !== undefined && (obj.name = message.name);
        message.text !== undefined && (obj.text = message.text);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseEntity);
        message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
        message.text = (_b = object.text) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseBlock = {};
exports.Block = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.boundingBox !== undefined) {
            exports.Polygon.encode(message.boundingBox, writer.uint32(10).fork()).ldelim();
        }
        for (const v of message.lines) {
            exports.Line.encode(v, writer.uint32(18).fork()).ldelim();
        }
        for (const v of message.languages) {
            exports.Block_DetectedLanguage.encode(v, writer.uint32(26).fork()).ldelim();
        }
        for (const v of message.textSegments) {
            exports.TextSegments.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({}, baseBlock);
        message.lines = [];
        message.languages = [];
        message.textSegments = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.boundingBox = exports.Polygon.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.lines.push(exports.Line.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.languages.push(exports.Block_DetectedLanguage.decode(reader, reader.uint32()));
                    break;
                case 4:
                    message.textSegments.push(exports.TextSegments.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseBlock);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromJSON(object.boundingBox)
                : undefined;
        message.lines = ((_a = object.lines) !== null && _a !== void 0 ? _a : []).map((e) => exports.Line.fromJSON(e));
        message.languages = ((_b = object.languages) !== null && _b !== void 0 ? _b : []).map((e) => exports.Block_DetectedLanguage.fromJSON(e));
        message.textSegments = ((_c = object.textSegments) !== null && _c !== void 0 ? _c : []).map((e) => exports.TextSegments.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.boundingBox !== undefined &&
            (obj.boundingBox = message.boundingBox
                ? exports.Polygon.toJSON(message.boundingBox)
                : undefined);
        if (message.lines) {
            obj.lines = message.lines.map((e) => (e ? exports.Line.toJSON(e) : undefined));
        }
        else {
            obj.lines = [];
        }
        if (message.languages) {
            obj.languages = message.languages.map((e) => e ? exports.Block_DetectedLanguage.toJSON(e) : undefined);
        }
        else {
            obj.languages = [];
        }
        if (message.textSegments) {
            obj.textSegments = message.textSegments.map((e) => e ? exports.TextSegments.toJSON(e) : undefined);
        }
        else {
            obj.textSegments = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseBlock);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromPartial(object.boundingBox)
                : undefined;
        message.lines = ((_a = object.lines) === null || _a === void 0 ? void 0 : _a.map((e) => exports.Line.fromPartial(e))) || [];
        message.languages =
            ((_b = object.languages) === null || _b === void 0 ? void 0 : _b.map((e) => exports.Block_DetectedLanguage.fromPartial(e))) || [];
        message.textSegments = ((_c = object.textSegments) === null || _c === void 0 ? void 0 : _c.map((e) => exports.TextSegments.fromPartial(e))) || [];
        return message;
    },
};
const baseBlock_DetectedLanguage = { languageCode: '' };
exports.Block_DetectedLanguage = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.languageCode !== '') {
            writer.uint32(10).string(message.languageCode);
        }
        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({}, baseBlock_DetectedLanguage);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.languageCode = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseBlock_DetectedLanguage);
        message.languageCode =
            object.languageCode !== undefined && object.languageCode !== null
                ? String(object.languageCode)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.languageCode !== undefined && (obj.languageCode = message.languageCode);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseBlock_DetectedLanguage);
        message.languageCode = (_a = object.languageCode) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseLine = { text: '', orientation: 0 };
exports.Line = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.boundingBox !== undefined) {
            exports.Polygon.encode(message.boundingBox, writer.uint32(10).fork()).ldelim();
        }
        if (message.text !== '') {
            writer.uint32(18).string(message.text);
        }
        for (const v of message.words) {
            exports.Word.encode(v, writer.uint32(26).fork()).ldelim();
        }
        for (const v of message.textSegments) {
            exports.TextSegments.encode(v, writer.uint32(34).fork()).ldelim();
        }
        if (message.orientation !== 0) {
            writer.uint32(40).int32(message.orientation);
        }
        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({}, baseLine);
        message.words = [];
        message.textSegments = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.boundingBox = exports.Polygon.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.text = reader.string();
                    break;
                case 3:
                    message.words.push(exports.Word.decode(reader, reader.uint32()));
                    break;
                case 4:
                    message.textSegments.push(exports.TextSegments.decode(reader, reader.uint32()));
                    break;
                case 5:
                    message.orientation = reader.int32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseLine);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromJSON(object.boundingBox)
                : undefined;
        message.text = object.text !== undefined && object.text !== null ? String(object.text) : '';
        message.words = ((_a = object.words) !== null && _a !== void 0 ? _a : []).map((e) => exports.Word.fromJSON(e));
        message.textSegments = ((_b = object.textSegments) !== null && _b !== void 0 ? _b : []).map((e) => exports.TextSegments.fromJSON(e));
        message.orientation =
            object.orientation !== undefined && object.orientation !== null
                ? angleFromJSON(object.orientation)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.boundingBox !== undefined &&
            (obj.boundingBox = message.boundingBox
                ? exports.Polygon.toJSON(message.boundingBox)
                : undefined);
        message.text !== undefined && (obj.text = message.text);
        if (message.words) {
            obj.words = message.words.map((e) => (e ? exports.Word.toJSON(e) : undefined));
        }
        else {
            obj.words = [];
        }
        if (message.textSegments) {
            obj.textSegments = message.textSegments.map((e) => e ? exports.TextSegments.toJSON(e) : undefined);
        }
        else {
            obj.textSegments = [];
        }
        message.orientation !== undefined && (obj.orientation = angleToJSON(message.orientation));
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = Object.assign({}, baseLine);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromPartial(object.boundingBox)
                : undefined;
        message.text = (_a = object.text) !== null && _a !== void 0 ? _a : '';
        message.words = ((_b = object.words) === null || _b === void 0 ? void 0 : _b.map((e) => exports.Word.fromPartial(e))) || [];
        message.textSegments = ((_c = object.textSegments) === null || _c === void 0 ? void 0 : _c.map((e) => exports.TextSegments.fromPartial(e))) || [];
        message.orientation = (_d = object.orientation) !== null && _d !== void 0 ? _d : 0;
        return message;
    },
};
const baseWord = { text: '', entityIndex: 0 };
exports.Word = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.boundingBox !== undefined) {
            exports.Polygon.encode(message.boundingBox, writer.uint32(10).fork()).ldelim();
        }
        if (message.text !== '') {
            writer.uint32(18).string(message.text);
        }
        if (message.entityIndex !== 0) {
            writer.uint32(24).int64(message.entityIndex);
        }
        for (const v of message.textSegments) {
            exports.TextSegments.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({}, baseWord);
        message.textSegments = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.boundingBox = exports.Polygon.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.text = reader.string();
                    break;
                case 3:
                    message.entityIndex = longToNumber(reader.int64());
                    break;
                case 4:
                    message.textSegments.push(exports.TextSegments.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseWord);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromJSON(object.boundingBox)
                : undefined;
        message.text = object.text !== undefined && object.text !== null ? String(object.text) : '';
        message.entityIndex =
            object.entityIndex !== undefined && object.entityIndex !== null
                ? Number(object.entityIndex)
                : 0;
        message.textSegments = ((_a = object.textSegments) !== null && _a !== void 0 ? _a : []).map((e) => exports.TextSegments.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.boundingBox !== undefined &&
            (obj.boundingBox = message.boundingBox
                ? exports.Polygon.toJSON(message.boundingBox)
                : undefined);
        message.text !== undefined && (obj.text = message.text);
        message.entityIndex !== undefined && (obj.entityIndex = Math.round(message.entityIndex));
        if (message.textSegments) {
            obj.textSegments = message.textSegments.map((e) => e ? exports.TextSegments.toJSON(e) : undefined);
        }
        else {
            obj.textSegments = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseWord);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromPartial(object.boundingBox)
                : undefined;
        message.text = (_a = object.text) !== null && _a !== void 0 ? _a : '';
        message.entityIndex = (_b = object.entityIndex) !== null && _b !== void 0 ? _b : 0;
        message.textSegments = ((_c = object.textSegments) === null || _c === void 0 ? void 0 : _c.map((e) => exports.TextSegments.fromPartial(e))) || [];
        return message;
    },
};
const baseTextSegments = { startIndex: 0, length: 0 };
exports.TextSegments = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.startIndex !== 0) {
            writer.uint32(8).int64(message.startIndex);
        }
        if (message.length !== 0) {
            writer.uint32(16).int64(message.length);
        }
        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({}, baseTextSegments);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.startIndex = longToNumber(reader.int64());
                    break;
                case 2:
                    message.length = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseTextSegments);
        message.startIndex =
            object.startIndex !== undefined && object.startIndex !== null
                ? Number(object.startIndex)
                : 0;
        message.length =
            object.length !== undefined && object.length !== null ? Number(object.length) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.startIndex !== undefined && (obj.startIndex = Math.round(message.startIndex));
        message.length !== undefined && (obj.length = Math.round(message.length));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseTextSegments);
        message.startIndex = (_a = object.startIndex) !== null && _a !== void 0 ? _a : 0;
        message.length = (_b = object.length) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseTable = { rowCount: 0, columnCount: 0 };
exports.Table = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.boundingBox !== undefined) {
            exports.Polygon.encode(message.boundingBox, writer.uint32(10).fork()).ldelim();
        }
        if (message.rowCount !== 0) {
            writer.uint32(16).int64(message.rowCount);
        }
        if (message.columnCount !== 0) {
            writer.uint32(24).int64(message.columnCount);
        }
        for (const v of message.cells) {
            exports.TableCell.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({}, baseTable);
        message.cells = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.boundingBox = exports.Polygon.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.rowCount = longToNumber(reader.int64());
                    break;
                case 3:
                    message.columnCount = longToNumber(reader.int64());
                    break;
                case 4:
                    message.cells.push(exports.TableCell.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseTable);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromJSON(object.boundingBox)
                : undefined;
        message.rowCount =
            object.rowCount !== undefined && object.rowCount !== null ? Number(object.rowCount) : 0;
        message.columnCount =
            object.columnCount !== undefined && object.columnCount !== null
                ? Number(object.columnCount)
                : 0;
        message.cells = ((_a = object.cells) !== null && _a !== void 0 ? _a : []).map((e) => exports.TableCell.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.boundingBox !== undefined &&
            (obj.boundingBox = message.boundingBox
                ? exports.Polygon.toJSON(message.boundingBox)
                : undefined);
        message.rowCount !== undefined && (obj.rowCount = Math.round(message.rowCount));
        message.columnCount !== undefined && (obj.columnCount = Math.round(message.columnCount));
        if (message.cells) {
            obj.cells = message.cells.map((e) => (e ? exports.TableCell.toJSON(e) : undefined));
        }
        else {
            obj.cells = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseTable);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromPartial(object.boundingBox)
                : undefined;
        message.rowCount = (_a = object.rowCount) !== null && _a !== void 0 ? _a : 0;
        message.columnCount = (_b = object.columnCount) !== null && _b !== void 0 ? _b : 0;
        message.cells = ((_c = object.cells) === null || _c === void 0 ? void 0 : _c.map((e) => exports.TableCell.fromPartial(e))) || [];
        return message;
    },
};
const baseTableCell = { rowIndex: 0, columnIndex: 0, columnSpan: 0, rowSpan: 0, text: '' };
exports.TableCell = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.boundingBox !== undefined) {
            exports.Polygon.encode(message.boundingBox, writer.uint32(10).fork()).ldelim();
        }
        if (message.rowIndex !== 0) {
            writer.uint32(16).int64(message.rowIndex);
        }
        if (message.columnIndex !== 0) {
            writer.uint32(24).int64(message.columnIndex);
        }
        if (message.columnSpan !== 0) {
            writer.uint32(32).int64(message.columnSpan);
        }
        if (message.rowSpan !== 0) {
            writer.uint32(40).int64(message.rowSpan);
        }
        if (message.text !== '') {
            writer.uint32(50).string(message.text);
        }
        for (const v of message.textSegments) {
            exports.TextSegments.encode(v, writer.uint32(58).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({}, baseTableCell);
        message.textSegments = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.boundingBox = exports.Polygon.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.rowIndex = longToNumber(reader.int64());
                    break;
                case 3:
                    message.columnIndex = longToNumber(reader.int64());
                    break;
                case 4:
                    message.columnSpan = longToNumber(reader.int64());
                    break;
                case 5:
                    message.rowSpan = longToNumber(reader.int64());
                    break;
                case 6:
                    message.text = reader.string();
                    break;
                case 7:
                    message.textSegments.push(exports.TextSegments.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseTableCell);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromJSON(object.boundingBox)
                : undefined;
        message.rowIndex =
            object.rowIndex !== undefined && object.rowIndex !== null ? Number(object.rowIndex) : 0;
        message.columnIndex =
            object.columnIndex !== undefined && object.columnIndex !== null
                ? Number(object.columnIndex)
                : 0;
        message.columnSpan =
            object.columnSpan !== undefined && object.columnSpan !== null
                ? Number(object.columnSpan)
                : 0;
        message.rowSpan =
            object.rowSpan !== undefined && object.rowSpan !== null ? Number(object.rowSpan) : 0;
        message.text = object.text !== undefined && object.text !== null ? String(object.text) : '';
        message.textSegments = ((_a = object.textSegments) !== null && _a !== void 0 ? _a : []).map((e) => exports.TextSegments.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.boundingBox !== undefined &&
            (obj.boundingBox = message.boundingBox
                ? exports.Polygon.toJSON(message.boundingBox)
                : undefined);
        message.rowIndex !== undefined && (obj.rowIndex = Math.round(message.rowIndex));
        message.columnIndex !== undefined && (obj.columnIndex = Math.round(message.columnIndex));
        message.columnSpan !== undefined && (obj.columnSpan = Math.round(message.columnSpan));
        message.rowSpan !== undefined && (obj.rowSpan = Math.round(message.rowSpan));
        message.text !== undefined && (obj.text = message.text);
        if (message.textSegments) {
            obj.textSegments = message.textSegments.map((e) => e ? exports.TextSegments.toJSON(e) : undefined);
        }
        else {
            obj.textSegments = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f;
        const message = Object.assign({}, baseTableCell);
        message.boundingBox =
            object.boundingBox !== undefined && object.boundingBox !== null
                ? exports.Polygon.fromPartial(object.boundingBox)
                : undefined;
        message.rowIndex = (_a = object.rowIndex) !== null && _a !== void 0 ? _a : 0;
        message.columnIndex = (_b = object.columnIndex) !== null && _b !== void 0 ? _b : 0;
        message.columnSpan = (_c = object.columnSpan) !== null && _c !== void 0 ? _c : 0;
        message.rowSpan = (_d = object.rowSpan) !== null && _d !== void 0 ? _d : 0;
        message.text = (_e = object.text) !== null && _e !== void 0 ? _e : '';
        message.textSegments = ((_f = object.textSegments) === null || _f === void 0 ? void 0 : _f.map((e) => exports.TextSegments.fromPartial(e))) || [];
        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 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();
}
