"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpeakerStatistics = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const utterance_statistics_1 = require("../../../../../yandex/cloud/speechsense/v1/analysis/utterance_statistics");
const statistics_common_1 = require("../../../../../yandex/cloud/speechsense/v1/analysis/statistics_common");
exports.protobufPackage = 'yandex.cloud.speechsense.v1.analysis';
const baseSpeakerStatistics = { speakerTag: '', utteranceCount: 0 };
exports.SpeakerStatistics = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.speakerTag !== '') {
            writer.uint32(10).string(message.speakerTag);
        }
        if (message.completeStatistics !== undefined) {
            utterance_statistics_1.UtteranceStatistics.encode(message.completeStatistics, writer.uint32(18).fork()).ldelim();
        }
        if (message.wordsPerUtterance !== undefined) {
            statistics_common_1.DescriptiveStatistics.encode(message.wordsPerUtterance, writer.uint32(26).fork()).ldelim();
        }
        if (message.lettersPerUtterance !== undefined) {
            statistics_common_1.DescriptiveStatistics.encode(message.lettersPerUtterance, writer.uint32(34).fork()).ldelim();
        }
        if (message.utteranceCount !== 0) {
            writer.uint32(40).int64(message.utteranceCount);
        }
        if (message.utteranceDurationEstimation !== undefined) {
            statistics_common_1.DescriptiveStatistics.encode(message.utteranceDurationEstimation, writer.uint32(50).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({}, baseSpeakerStatistics);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.speakerTag = reader.string();
                    break;
                case 2:
                    message.completeStatistics = utterance_statistics_1.UtteranceStatistics.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.wordsPerUtterance = statistics_common_1.DescriptiveStatistics.decode(reader, reader.uint32());
                    break;
                case 4:
                    message.lettersPerUtterance = statistics_common_1.DescriptiveStatistics.decode(reader, reader.uint32());
                    break;
                case 5:
                    message.utteranceCount = longToNumber(reader.int64());
                    break;
                case 6:
                    message.utteranceDurationEstimation = statistics_common_1.DescriptiveStatistics.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseSpeakerStatistics);
        message.speakerTag =
            object.speakerTag !== undefined && object.speakerTag !== null
                ? String(object.speakerTag)
                : '';
        message.completeStatistics =
            object.completeStatistics !== undefined && object.completeStatistics !== null
                ? utterance_statistics_1.UtteranceStatistics.fromJSON(object.completeStatistics)
                : undefined;
        message.wordsPerUtterance =
            object.wordsPerUtterance !== undefined && object.wordsPerUtterance !== null
                ? statistics_common_1.DescriptiveStatistics.fromJSON(object.wordsPerUtterance)
                : undefined;
        message.lettersPerUtterance =
            object.lettersPerUtterance !== undefined && object.lettersPerUtterance !== null
                ? statistics_common_1.DescriptiveStatistics.fromJSON(object.lettersPerUtterance)
                : undefined;
        message.utteranceCount =
            object.utteranceCount !== undefined && object.utteranceCount !== null
                ? Number(object.utteranceCount)
                : 0;
        message.utteranceDurationEstimation =
            object.utteranceDurationEstimation !== undefined &&
                object.utteranceDurationEstimation !== null
                ? statistics_common_1.DescriptiveStatistics.fromJSON(object.utteranceDurationEstimation)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.speakerTag !== undefined && (obj.speakerTag = message.speakerTag);
        message.completeStatistics !== undefined &&
            (obj.completeStatistics = message.completeStatistics
                ? utterance_statistics_1.UtteranceStatistics.toJSON(message.completeStatistics)
                : undefined);
        message.wordsPerUtterance !== undefined &&
            (obj.wordsPerUtterance = message.wordsPerUtterance
                ? statistics_common_1.DescriptiveStatistics.toJSON(message.wordsPerUtterance)
                : undefined);
        message.lettersPerUtterance !== undefined &&
            (obj.lettersPerUtterance = message.lettersPerUtterance
                ? statistics_common_1.DescriptiveStatistics.toJSON(message.lettersPerUtterance)
                : undefined);
        message.utteranceCount !== undefined &&
            (obj.utteranceCount = Math.round(message.utteranceCount));
        message.utteranceDurationEstimation !== undefined &&
            (obj.utteranceDurationEstimation = message.utteranceDurationEstimation
                ? statistics_common_1.DescriptiveStatistics.toJSON(message.utteranceDurationEstimation)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseSpeakerStatistics);
        message.speakerTag = (_a = object.speakerTag) !== null && _a !== void 0 ? _a : '';
        message.completeStatistics =
            object.completeStatistics !== undefined && object.completeStatistics !== null
                ? utterance_statistics_1.UtteranceStatistics.fromPartial(object.completeStatistics)
                : undefined;
        message.wordsPerUtterance =
            object.wordsPerUtterance !== undefined && object.wordsPerUtterance !== null
                ? statistics_common_1.DescriptiveStatistics.fromPartial(object.wordsPerUtterance)
                : undefined;
        message.lettersPerUtterance =
            object.lettersPerUtterance !== undefined && object.lettersPerUtterance !== null
                ? statistics_common_1.DescriptiveStatistics.fromPartial(object.lettersPerUtterance)
                : undefined;
        message.utteranceCount = (_b = object.utteranceCount) !== null && _b !== void 0 ? _b : 0;
        message.utteranceDurationEstimation =
            object.utteranceDurationEstimation !== undefined &&
                object.utteranceDurationEstimation !== null
                ? statistics_common_1.DescriptiveStatistics.fromPartial(object.utteranceDurationEstimation)
                : undefined;
        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();
}
