"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Report_NetCodesEntry = exports.Report_HttpCodesEntry = exports.Report = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const quantiles_1 = require("../../../../../../../yandex/cloud/loadtesting/api/v1/common/quantiles");
exports.protobufPackage = 'yandex.cloud.loadtesting.api.v1.report.table';
const baseReport = {};
exports.Report = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        Object.entries(message.httpCodes).forEach(([key, value]) => {
            exports.Report_HttpCodesEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
        });
        Object.entries(message.netCodes).forEach(([key, value]) => {
            exports.Report_NetCodesEntry.encode({ key: key, value }, writer.uint32(18).fork()).ldelim();
        });
        if (message.quantiles !== undefined) {
            quantiles_1.Quantiles.encode(message.quantiles, 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({}, baseReport);
        message.httpCodes = {};
        message.netCodes = {};
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    const entry1 = exports.Report_HttpCodesEntry.decode(reader, reader.uint32());
                    if (entry1.value !== undefined) {
                        message.httpCodes[entry1.key] = entry1.value;
                    }
                    break;
                case 2:
                    const entry2 = exports.Report_NetCodesEntry.decode(reader, reader.uint32());
                    if (entry2.value !== undefined) {
                        message.netCodes[entry2.key] = entry2.value;
                    }
                    break;
                case 3:
                    message.quantiles = quantiles_1.Quantiles.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseReport);
        message.httpCodes = Object.entries((_a = object.httpCodes) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[Number(key)] = Number(value);
            return acc;
        }, {});
        message.netCodes = Object.entries((_b = object.netCodes) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
            acc[Number(key)] = Number(value);
            return acc;
        }, {});
        message.quantiles =
            object.quantiles !== undefined && object.quantiles !== null
                ? quantiles_1.Quantiles.fromJSON(object.quantiles)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        obj.httpCodes = {};
        if (message.httpCodes) {
            Object.entries(message.httpCodes).forEach(([k, v]) => {
                obj.httpCodes[k] = Math.round(v);
            });
        }
        obj.netCodes = {};
        if (message.netCodes) {
            Object.entries(message.netCodes).forEach(([k, v]) => {
                obj.netCodes[k] = Math.round(v);
            });
        }
        message.quantiles !== undefined &&
            (obj.quantiles = message.quantiles ? quantiles_1.Quantiles.toJSON(message.quantiles) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseReport);
        message.httpCodes = Object.entries((_a = object.httpCodes) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[Number(key)] = Number(value);
            }
            return acc;
        }, {});
        message.netCodes = Object.entries((_b = object.netCodes) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[Number(key)] = Number(value);
            }
            return acc;
        }, {});
        message.quantiles =
            object.quantiles !== undefined && object.quantiles !== null
                ? quantiles_1.Quantiles.fromPartial(object.quantiles)
                : undefined;
        return message;
    },
};
const baseReport_HttpCodesEntry = { key: 0, value: 0 };
exports.Report_HttpCodesEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.key !== 0) {
            writer.uint32(8).int64(message.key);
        }
        if (message.value !== 0) {
            writer.uint32(16).int64(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({}, baseReport_HttpCodesEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.key = longToNumber(reader.int64());
                    break;
                case 2:
                    message.value = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseReport_HttpCodesEntry);
        message.key = object.key !== undefined && object.key !== null ? Number(object.key) : 0;
        message.value =
            object.value !== undefined && object.value !== null ? Number(object.value) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.key !== undefined && (obj.key = Math.round(message.key));
        message.value !== undefined && (obj.value = Math.round(message.value));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseReport_HttpCodesEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : 0;
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseReport_NetCodesEntry = { key: 0, value: 0 };
exports.Report_NetCodesEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.key !== 0) {
            writer.uint32(8).int64(message.key);
        }
        if (message.value !== 0) {
            writer.uint32(16).int64(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({}, baseReport_NetCodesEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.key = longToNumber(reader.int64());
                    break;
                case 2:
                    message.value = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseReport_NetCodesEntry);
        message.key = object.key !== undefined && object.key !== null ? Number(object.key) : 0;
        message.value =
            object.value !== undefined && object.value !== null ? Number(object.value) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.key !== undefined && (obj.key = Math.round(message.key));
        message.value !== undefined && (obj.value = Math.round(message.value));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseReport_NetCodesEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : 0;
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
var globalThis = (() => {
    if (typeof globalThis !== 'undefined')
        return globalThis;
    if (typeof self !== 'undefined')
        return self;
    if (typeof window !== 'undefined')
        return window;
    if (typeof global !== 'undefined')
        return global;
    throw 'Unable to locate global object';
})();
function 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();
}
