"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RateLimit_Limit = exports.RateLimit = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
exports.protobufPackage = 'yandex.cloud.apploadbalancer.v1';
const baseRateLimit = {};
exports.RateLimit = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.allRequests !== undefined) {
            exports.RateLimit_Limit.encode(message.allRequests, writer.uint32(26).fork()).ldelim();
        }
        if (message.requestsPerIp !== undefined) {
            exports.RateLimit_Limit.encode(message.requestsPerIp, 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({}, baseRateLimit);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 3:
                    message.allRequests = exports.RateLimit_Limit.decode(reader, reader.uint32());
                    break;
                case 4:
                    message.requestsPerIp = exports.RateLimit_Limit.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseRateLimit);
        message.allRequests =
            object.allRequests !== undefined && object.allRequests !== null
                ? exports.RateLimit_Limit.fromJSON(object.allRequests)
                : undefined;
        message.requestsPerIp =
            object.requestsPerIp !== undefined && object.requestsPerIp !== null
                ? exports.RateLimit_Limit.fromJSON(object.requestsPerIp)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.allRequests !== undefined &&
            (obj.allRequests = message.allRequests
                ? exports.RateLimit_Limit.toJSON(message.allRequests)
                : undefined);
        message.requestsPerIp !== undefined &&
            (obj.requestsPerIp = message.requestsPerIp
                ? exports.RateLimit_Limit.toJSON(message.requestsPerIp)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseRateLimit);
        message.allRequests =
            object.allRequests !== undefined && object.allRequests !== null
                ? exports.RateLimit_Limit.fromPartial(object.allRequests)
                : undefined;
        message.requestsPerIp =
            object.requestsPerIp !== undefined && object.requestsPerIp !== null
                ? exports.RateLimit_Limit.fromPartial(object.requestsPerIp)
                : undefined;
        return message;
    },
};
const baseRateLimit_Limit = {};
exports.RateLimit_Limit = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.perSecond !== undefined) {
            writer.uint32(8).int64(message.perSecond);
        }
        if (message.perMinute !== undefined) {
            writer.uint32(16).int64(message.perMinute);
        }
        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({}, baseRateLimit_Limit);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.perSecond = longToNumber(reader.int64());
                    break;
                case 2:
                    message.perMinute = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseRateLimit_Limit);
        message.perSecond =
            object.perSecond !== undefined && object.perSecond !== null
                ? Number(object.perSecond)
                : undefined;
        message.perMinute =
            object.perMinute !== undefined && object.perMinute !== null
                ? Number(object.perMinute)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.perSecond !== undefined && (obj.perSecond = Math.round(message.perSecond));
        message.perMinute !== undefined && (obj.perMinute = Math.round(message.perMinute));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseRateLimit_Limit);
        message.perSecond = (_a = object.perSecond) !== null && _a !== void 0 ? _a : undefined;
        message.perMinute = (_b = object.perMinute) !== null && _b !== void 0 ? _b : 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();
}
