"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rule = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const resource_1 = require("../../../../yandex/cloud/cdn/v1/resource");
exports.protobufPackage = 'yandex.cloud.cdn.v1';
const baseRule = { id: 0, name: '', rulePattern: '' };
exports.Rule = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== 0) {
            writer.uint32(8).int64(message.id);
        }
        if (message.name !== '') {
            writer.uint32(18).string(message.name);
        }
        if (message.rulePattern !== '') {
            writer.uint32(26).string(message.rulePattern);
        }
        if (message.options !== undefined) {
            resource_1.ResourceOptions.encode(message.options, 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({}, baseRule);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = longToNumber(reader.int64());
                    break;
                case 2:
                    message.name = reader.string();
                    break;
                case 3:
                    message.rulePattern = reader.string();
                    break;
                case 4:
                    message.options = resource_1.ResourceOptions.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseRule);
        message.id = object.id !== undefined && object.id !== null ? Number(object.id) : 0;
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.rulePattern =
            object.rulePattern !== undefined && object.rulePattern !== null
                ? String(object.rulePattern)
                : '';
        message.options =
            object.options !== undefined && object.options !== null
                ? resource_1.ResourceOptions.fromJSON(object.options)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = Math.round(message.id));
        message.name !== undefined && (obj.name = message.name);
        message.rulePattern !== undefined && (obj.rulePattern = message.rulePattern);
        message.options !== undefined &&
            (obj.options = message.options ? resource_1.ResourceOptions.toJSON(message.options) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseRule);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : 0;
        message.name = (_b = object.name) !== null && _b !== void 0 ? _b : '';
        message.rulePattern = (_c = object.rulePattern) !== null && _c !== void 0 ? _c : '';
        message.options =
            object.options !== undefined && object.options !== null
                ? resource_1.ResourceOptions.fromPartial(object.options)
                : 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();
}
