"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic = exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic = exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic = exports.AdvancedRateLimiterRule_DynamicQuota = exports.AdvancedRateLimiterRule_StaticQuota = exports.AdvancedRateLimiterRule = exports.AdvancedRateLimiterProfile_LabelsEntry = exports.AdvancedRateLimiterProfile = exports.advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeToJSON = exports.advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeFromJSON = exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type = exports.advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeToJSON = exports.advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeFromJSON = exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type = exports.advancedRateLimiterRule_ActionToJSON = exports.advancedRateLimiterRule_ActionFromJSON = exports.AdvancedRateLimiterRule_Action = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const security_profile_1 = require("../../../../../yandex/cloud/smartwebsecurity/v1/security_profile");
const timestamp_1 = require("../../../../../google/protobuf/timestamp");
exports.protobufPackage = 'yandex.cloud.smartwebsecurity.v1.advanced_rate_limiter';
/** Type of action to perform if this rule matched. */
var AdvancedRateLimiterRule_Action;
(function (AdvancedRateLimiterRule_Action) {
    AdvancedRateLimiterRule_Action[AdvancedRateLimiterRule_Action["ACTION_UNSPECIFIED"] = 0] = "ACTION_UNSPECIFIED";
    /** DENY - Deny request. */
    AdvancedRateLimiterRule_Action[AdvancedRateLimiterRule_Action["DENY"] = 1] = "DENY";
    AdvancedRateLimiterRule_Action[AdvancedRateLimiterRule_Action["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(AdvancedRateLimiterRule_Action = exports.AdvancedRateLimiterRule_Action || (exports.AdvancedRateLimiterRule_Action = {}));
function advancedRateLimiterRule_ActionFromJSON(object) {
    switch (object) {
        case 0:
        case 'ACTION_UNSPECIFIED':
            return AdvancedRateLimiterRule_Action.ACTION_UNSPECIFIED;
        case 1:
        case 'DENY':
            return AdvancedRateLimiterRule_Action.DENY;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return AdvancedRateLimiterRule_Action.UNRECOGNIZED;
    }
}
exports.advancedRateLimiterRule_ActionFromJSON = advancedRateLimiterRule_ActionFromJSON;
function advancedRateLimiterRule_ActionToJSON(object) {
    switch (object) {
        case AdvancedRateLimiterRule_Action.ACTION_UNSPECIFIED:
            return 'ACTION_UNSPECIFIED';
        case AdvancedRateLimiterRule_Action.DENY:
            return 'DENY';
        default:
            return 'UNKNOWN';
    }
}
exports.advancedRateLimiterRule_ActionToJSON = advancedRateLimiterRule_ActionToJSON;
/** Type of simple characteristic. */
var AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type;
(function (AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type) {
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type["TYPE_UNSPECIFIED"] = 0] = "TYPE_UNSPECIFIED";
    /** REQUEST_PATH - HTTP Request path. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type["REQUEST_PATH"] = 1] = "REQUEST_PATH";
    /** HTTP_METHOD - HTTP Method. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type["HTTP_METHOD"] = 2] = "HTTP_METHOD";
    /** IP - IP address. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type["IP"] = 3] = "IP";
    /** GEO - Region. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type["GEO"] = 4] = "GEO";
    /** HOST - Host. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type["HOST"] = 5] = "HOST";
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type = exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type || (exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type = {}));
function advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeFromJSON(object) {
    switch (object) {
        case 0:
        case 'TYPE_UNSPECIFIED':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.TYPE_UNSPECIFIED;
        case 1:
        case 'REQUEST_PATH':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.REQUEST_PATH;
        case 2:
        case 'HTTP_METHOD':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.HTTP_METHOD;
        case 3:
        case 'IP':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.IP;
        case 4:
        case 'GEO':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.GEO;
        case 5:
        case 'HOST':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.HOST;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.UNRECOGNIZED;
    }
}
exports.advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeFromJSON = advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeFromJSON;
function advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeToJSON(object) {
    switch (object) {
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.TYPE_UNSPECIFIED:
            return 'TYPE_UNSPECIFIED';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.REQUEST_PATH:
            return 'REQUEST_PATH';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.HTTP_METHOD:
            return 'HTTP_METHOD';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.IP:
            return 'IP';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.GEO:
            return 'GEO';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_Type.HOST:
            return 'HOST';
        default:
            return 'UNKNOWN';
    }
}
exports.advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeToJSON = advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeToJSON;
/** Type of key characteristic. */
var AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type;
(function (AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type) {
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type["TYPE_UNSPECIFIED"] = 0] = "TYPE_UNSPECIFIED";
    /** COOKIE_KEY - HTTP cookie key. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type["COOKIE_KEY"] = 1] = "COOKIE_KEY";
    /** HEADER_KEY - HTTP header key. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type["HEADER_KEY"] = 2] = "HEADER_KEY";
    /** QUERY_KEY - Query params key. */
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type["QUERY_KEY"] = 3] = "QUERY_KEY";
    AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type[AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type = exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type || (exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type = {}));
function advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeFromJSON(object) {
    switch (object) {
        case 0:
        case 'TYPE_UNSPECIFIED':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.TYPE_UNSPECIFIED;
        case 1:
        case 'COOKIE_KEY':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.COOKIE_KEY;
        case 2:
        case 'HEADER_KEY':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.HEADER_KEY;
        case 3:
        case 'QUERY_KEY':
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.QUERY_KEY;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.UNRECOGNIZED;
    }
}
exports.advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeFromJSON = advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeFromJSON;
function advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeToJSON(object) {
    switch (object) {
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.TYPE_UNSPECIFIED:
            return 'TYPE_UNSPECIFIED';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.COOKIE_KEY:
            return 'COOKIE_KEY';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.HEADER_KEY:
            return 'HEADER_KEY';
        case AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_Type.QUERY_KEY:
            return 'QUERY_KEY';
        default:
            return 'UNKNOWN';
    }
}
exports.advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeToJSON = advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeToJSON;
const baseAdvancedRateLimiterProfile = {
    id: '',
    folderId: '',
    name: '',
    description: '',
    cloudId: '',
};
exports.AdvancedRateLimiterProfile = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.folderId !== '') {
            writer.uint32(18).string(message.folderId);
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.AdvancedRateLimiterProfile_LabelsEntry.encode({ key: key, value }, writer.uint32(26).fork()).ldelim();
        });
        if (message.name !== '') {
            writer.uint32(34).string(message.name);
        }
        if (message.description !== '') {
            writer.uint32(42).string(message.description);
        }
        for (const v of message.advancedRateLimiterRules) {
            exports.AdvancedRateLimiterRule.encode(v, writer.uint32(50).fork()).ldelim();
        }
        if (message.createdAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(58).fork()).ldelim();
        }
        if (message.cloudId !== '') {
            writer.uint32(74).string(message.cloudId);
        }
        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({}, baseAdvancedRateLimiterProfile);
        message.labels = {};
        message.advancedRateLimiterRules = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.folderId = reader.string();
                    break;
                case 3:
                    const entry3 = exports.AdvancedRateLimiterProfile_LabelsEntry.decode(reader, reader.uint32());
                    if (entry3.value !== undefined) {
                        message.labels[entry3.key] = entry3.value;
                    }
                    break;
                case 4:
                    message.name = reader.string();
                    break;
                case 5:
                    message.description = reader.string();
                    break;
                case 6:
                    message.advancedRateLimiterRules.push(exports.AdvancedRateLimiterRule.decode(reader, reader.uint32()));
                    break;
                case 7:
                    message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 9:
                    message.cloudId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseAdvancedRateLimiterProfile);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.folderId =
            object.folderId !== undefined && object.folderId !== null
                ? String(object.folderId)
                : '';
        message.labels = Object.entries((_a = object.labels) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.advancedRateLimiterRules = ((_b = object.advancedRateLimiterRules) !== null && _b !== void 0 ? _b : []).map((e) => exports.AdvancedRateLimiterRule.fromJSON(e));
        message.createdAt =
            object.createdAt !== undefined && object.createdAt !== null
                ? fromJsonTimestamp(object.createdAt)
                : undefined;
        message.cloudId =
            object.cloudId !== undefined && object.cloudId !== null ? String(object.cloudId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.folderId !== undefined && (obj.folderId = message.folderId);
        obj.labels = {};
        if (message.labels) {
            Object.entries(message.labels).forEach(([k, v]) => {
                obj.labels[k] = v;
            });
        }
        message.name !== undefined && (obj.name = message.name);
        message.description !== undefined && (obj.description = message.description);
        if (message.advancedRateLimiterRules) {
            obj.advancedRateLimiterRules = message.advancedRateLimiterRules.map((e) => e ? exports.AdvancedRateLimiterRule.toJSON(e) : undefined);
        }
        else {
            obj.advancedRateLimiterRules = [];
        }
        message.createdAt !== undefined && (obj.createdAt = message.createdAt.toISOString());
        message.cloudId !== undefined && (obj.cloudId = message.cloudId);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        const message = Object.assign({}, baseAdvancedRateLimiterProfile);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.folderId = (_b = object.folderId) !== null && _b !== void 0 ? _b : '';
        message.labels = Object.entries((_c = object.labels) !== null && _c !== void 0 ? _c : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.name = (_d = object.name) !== null && _d !== void 0 ? _d : '';
        message.description = (_e = object.description) !== null && _e !== void 0 ? _e : '';
        message.advancedRateLimiterRules =
            ((_f = object.advancedRateLimiterRules) === null || _f === void 0 ? void 0 : _f.map((e) => exports.AdvancedRateLimiterRule.fromPartial(e))) ||
                [];
        message.createdAt = (_g = object.createdAt) !== null && _g !== void 0 ? _g : undefined;
        message.cloudId = (_h = object.cloudId) !== null && _h !== void 0 ? _h : '';
        return message;
    },
};
const baseAdvancedRateLimiterProfile_LabelsEntry = { key: '', value: '' };
exports.AdvancedRateLimiterProfile_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({}, baseAdvancedRateLimiterProfile_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({}, baseAdvancedRateLimiterProfile_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({}, baseAdvancedRateLimiterProfile_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseAdvancedRateLimiterRule = {
    name: '',
    priority: 0,
    description: '',
    dryRun: false,
};
exports.AdvancedRateLimiterRule = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.name !== '') {
            writer.uint32(10).string(message.name);
        }
        if (message.priority !== 0) {
            writer.uint32(16).int64(message.priority);
        }
        if (message.description !== '') {
            writer.uint32(26).string(message.description);
        }
        if (message.dryRun === true) {
            writer.uint32(32).bool(message.dryRun);
        }
        if (message.staticQuota !== undefined) {
            exports.AdvancedRateLimiterRule_StaticQuota.encode(message.staticQuota, writer.uint32(42).fork()).ldelim();
        }
        if (message.dynamicQuota !== undefined) {
            exports.AdvancedRateLimiterRule_DynamicQuota.encode(message.dynamicQuota, 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({}, baseAdvancedRateLimiterRule);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.name = reader.string();
                    break;
                case 2:
                    message.priority = longToNumber(reader.int64());
                    break;
                case 3:
                    message.description = reader.string();
                    break;
                case 4:
                    message.dryRun = reader.bool();
                    break;
                case 5:
                    message.staticQuota = exports.AdvancedRateLimiterRule_StaticQuota.decode(reader, reader.uint32());
                    break;
                case 6:
                    message.dynamicQuota = exports.AdvancedRateLimiterRule_DynamicQuota.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAdvancedRateLimiterRule);
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.priority =
            object.priority !== undefined && object.priority !== null ? Number(object.priority) : 0;
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.dryRun =
            object.dryRun !== undefined && object.dryRun !== null ? Boolean(object.dryRun) : false;
        message.staticQuota =
            object.staticQuota !== undefined && object.staticQuota !== null
                ? exports.AdvancedRateLimiterRule_StaticQuota.fromJSON(object.staticQuota)
                : undefined;
        message.dynamicQuota =
            object.dynamicQuota !== undefined && object.dynamicQuota !== null
                ? exports.AdvancedRateLimiterRule_DynamicQuota.fromJSON(object.dynamicQuota)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.name !== undefined && (obj.name = message.name);
        message.priority !== undefined && (obj.priority = Math.round(message.priority));
        message.description !== undefined && (obj.description = message.description);
        message.dryRun !== undefined && (obj.dryRun = message.dryRun);
        message.staticQuota !== undefined &&
            (obj.staticQuota = message.staticQuota
                ? exports.AdvancedRateLimiterRule_StaticQuota.toJSON(message.staticQuota)
                : undefined);
        message.dynamicQuota !== undefined &&
            (obj.dynamicQuota = message.dynamicQuota
                ? exports.AdvancedRateLimiterRule_DynamicQuota.toJSON(message.dynamicQuota)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = Object.assign({}, baseAdvancedRateLimiterRule);
        message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
        message.priority = (_b = object.priority) !== null && _b !== void 0 ? _b : 0;
        message.description = (_c = object.description) !== null && _c !== void 0 ? _c : '';
        message.dryRun = (_d = object.dryRun) !== null && _d !== void 0 ? _d : false;
        message.staticQuota =
            object.staticQuota !== undefined && object.staticQuota !== null
                ? exports.AdvancedRateLimiterRule_StaticQuota.fromPartial(object.staticQuota)
                : undefined;
        message.dynamicQuota =
            object.dynamicQuota !== undefined && object.dynamicQuota !== null
                ? exports.AdvancedRateLimiterRule_DynamicQuota.fromPartial(object.dynamicQuota)
                : undefined;
        return message;
    },
};
const baseAdvancedRateLimiterRule_StaticQuota = { action: 0, limit: 0, period: 0 };
exports.AdvancedRateLimiterRule_StaticQuota = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.action !== 0) {
            writer.uint32(8).int32(message.action);
        }
        if (message.condition !== undefined) {
            security_profile_1.Condition.encode(message.condition, writer.uint32(18).fork()).ldelim();
        }
        if (message.limit !== 0) {
            writer.uint32(24).int64(message.limit);
        }
        if (message.period !== 0) {
            writer.uint32(32).int64(message.period);
        }
        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({}, baseAdvancedRateLimiterRule_StaticQuota);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.action = reader.int32();
                    break;
                case 2:
                    message.condition = security_profile_1.Condition.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.limit = longToNumber(reader.int64());
                    break;
                case 4:
                    message.period = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAdvancedRateLimiterRule_StaticQuota);
        message.action =
            object.action !== undefined && object.action !== null
                ? advancedRateLimiterRule_ActionFromJSON(object.action)
                : 0;
        message.condition =
            object.condition !== undefined && object.condition !== null
                ? security_profile_1.Condition.fromJSON(object.condition)
                : undefined;
        message.limit =
            object.limit !== undefined && object.limit !== null ? Number(object.limit) : 0;
        message.period =
            object.period !== undefined && object.period !== null ? Number(object.period) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.action !== undefined &&
            (obj.action = advancedRateLimiterRule_ActionToJSON(message.action));
        message.condition !== undefined &&
            (obj.condition = message.condition ? security_profile_1.Condition.toJSON(message.condition) : undefined);
        message.limit !== undefined && (obj.limit = Math.round(message.limit));
        message.period !== undefined && (obj.period = Math.round(message.period));
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseAdvancedRateLimiterRule_StaticQuota);
        message.action = (_a = object.action) !== null && _a !== void 0 ? _a : 0;
        message.condition =
            object.condition !== undefined && object.condition !== null
                ? security_profile_1.Condition.fromPartial(object.condition)
                : undefined;
        message.limit = (_b = object.limit) !== null && _b !== void 0 ? _b : 0;
        message.period = (_c = object.period) !== null && _c !== void 0 ? _c : 0;
        return message;
    },
};
const baseAdvancedRateLimiterRule_DynamicQuota = { action: 0, limit: 0, period: 0 };
exports.AdvancedRateLimiterRule_DynamicQuota = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.action !== 0) {
            writer.uint32(8).int32(message.action);
        }
        if (message.condition !== undefined) {
            security_profile_1.Condition.encode(message.condition, writer.uint32(18).fork()).ldelim();
        }
        if (message.limit !== 0) {
            writer.uint32(24).int64(message.limit);
        }
        if (message.period !== 0) {
            writer.uint32(32).int64(message.period);
        }
        for (const v of message.characteristics) {
            exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic.encode(v, writer.uint32(42).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({}, baseAdvancedRateLimiterRule_DynamicQuota);
        message.characteristics = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.action = reader.int32();
                    break;
                case 2:
                    message.condition = security_profile_1.Condition.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.limit = longToNumber(reader.int64());
                    break;
                case 4:
                    message.period = longToNumber(reader.int64());
                    break;
                case 5:
                    message.characteristics.push(exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota);
        message.action =
            object.action !== undefined && object.action !== null
                ? advancedRateLimiterRule_ActionFromJSON(object.action)
                : 0;
        message.condition =
            object.condition !== undefined && object.condition !== null
                ? security_profile_1.Condition.fromJSON(object.condition)
                : undefined;
        message.limit =
            object.limit !== undefined && object.limit !== null ? Number(object.limit) : 0;
        message.period =
            object.period !== undefined && object.period !== null ? Number(object.period) : 0;
        message.characteristics = ((_a = object.characteristics) !== null && _a !== void 0 ? _a : []).map((e) => exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.action !== undefined &&
            (obj.action = advancedRateLimiterRule_ActionToJSON(message.action));
        message.condition !== undefined &&
            (obj.condition = message.condition ? security_profile_1.Condition.toJSON(message.condition) : undefined);
        message.limit !== undefined && (obj.limit = Math.round(message.limit));
        message.period !== undefined && (obj.period = Math.round(message.period));
        if (message.characteristics) {
            obj.characteristics = message.characteristics.map((e) => e ? exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic.toJSON(e) : undefined);
        }
        else {
            obj.characteristics = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota);
        message.action = (_a = object.action) !== null && _a !== void 0 ? _a : 0;
        message.condition =
            object.condition !== undefined && object.condition !== null
                ? security_profile_1.Condition.fromPartial(object.condition)
                : undefined;
        message.limit = (_b = object.limit) !== null && _b !== void 0 ? _b : 0;
        message.period = (_c = object.period) !== null && _c !== void 0 ? _c : 0;
        message.characteristics =
            ((_d = object.characteristics) === null || _d === void 0 ? void 0 : _d.map((e) => exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic.fromPartial(e))) || [];
        return message;
    },
};
const baseAdvancedRateLimiterRule_DynamicQuota_Characteristic = { caseInsensitive: false };
exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.simpleCharacteristic !== undefined) {
            exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic.encode(message.simpleCharacteristic, writer.uint32(10).fork()).ldelim();
        }
        if (message.keyCharacteristic !== undefined) {
            exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic.encode(message.keyCharacteristic, writer.uint32(18).fork()).ldelim();
        }
        if (message.caseInsensitive === true) {
            writer.uint32(80).bool(message.caseInsensitive);
        }
        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({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.simpleCharacteristic =
                        exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.keyCharacteristic =
                        exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic.decode(reader, reader.uint32());
                    break;
                case 10:
                    message.caseInsensitive = reader.bool();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic);
        message.simpleCharacteristic =
            object.simpleCharacteristic !== undefined && object.simpleCharacteristic !== null
                ? exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic.fromJSON(object.simpleCharacteristic)
                : undefined;
        message.keyCharacteristic =
            object.keyCharacteristic !== undefined && object.keyCharacteristic !== null
                ? exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic.fromJSON(object.keyCharacteristic)
                : undefined;
        message.caseInsensitive =
            object.caseInsensitive !== undefined && object.caseInsensitive !== null
                ? Boolean(object.caseInsensitive)
                : false;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.simpleCharacteristic !== undefined &&
            (obj.simpleCharacteristic = message.simpleCharacteristic
                ? exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic.toJSON(message.simpleCharacteristic)
                : undefined);
        message.keyCharacteristic !== undefined &&
            (obj.keyCharacteristic = message.keyCharacteristic
                ? exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic.toJSON(message.keyCharacteristic)
                : undefined);
        message.caseInsensitive !== undefined && (obj.caseInsensitive = message.caseInsensitive);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic);
        message.simpleCharacteristic =
            object.simpleCharacteristic !== undefined && object.simpleCharacteristic !== null
                ? exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic.fromPartial(object.simpleCharacteristic)
                : undefined;
        message.keyCharacteristic =
            object.keyCharacteristic !== undefined && object.keyCharacteristic !== null
                ? exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic.fromPartial(object.keyCharacteristic)
                : undefined;
        message.caseInsensitive = (_a = object.caseInsensitive) !== null && _a !== void 0 ? _a : false;
        return message;
    },
};
const baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic = {
    type: 0,
};
exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.type !== 0) {
            writer.uint32(8).int32(message.type);
        }
        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({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.type = reader.int32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic);
        message.type =
            object.type !== undefined && object.type !== null
                ? advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeFromJSON(object.type)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.type !== undefined &&
            (obj.type =
                advancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic_TypeToJSON(message.type));
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_SimpleCharacteristic);
        message.type = (_a = object.type) !== null && _a !== void 0 ? _a : 0;
        return message;
    },
};
const baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic = {
    type: 0,
    value: '',
};
exports.AdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.type !== 0) {
            writer.uint32(8).int32(message.type);
        }
        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({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.type = reader.int32();
                    break;
                case 2:
                    message.value = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic);
        message.type =
            object.type !== undefined && object.type !== null
                ? advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeFromJSON(object.type)
                : 0;
        message.value =
            object.value !== undefined && object.value !== null ? String(object.value) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.type !== undefined &&
            (obj.type =
                advancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic_TypeToJSON(message.type));
        message.value !== undefined && (obj.value = message.value);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseAdvancedRateLimiterRule_DynamicQuota_Characteristic_KeyCharacteristic);
        message.type = (_a = object.type) !== null && _a !== void 0 ? _a : 0;
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        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 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));
    }
}
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();
}
