"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceRulesServiceClient = exports.ResourceRulesServiceService = exports.DeleteResourceRuleMetadata = exports.DeleteResourceRuleRequest = exports.UpdateResourceRuleMetadata = exports.UpdateResourceRuleRequest = exports.GetResourceRuleRequest = exports.CreateResourceRuleMetadata = exports.CreateResourceRuleRequest = exports.ListResourceRulesResponse = exports.ListResourceRulesRequest = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const grpc_js_1 = require("@grpc/grpc-js");
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const resource_1 = require("../../../../yandex/cloud/cdn/v1/resource");
const rule_1 = require("../../../../yandex/cloud/cdn/v1/rule");
const operation_1 = require("../../../../yandex/cloud/operation/operation");
exports.protobufPackage = 'yandex.cloud.cdn.v1';
const baseListResourceRulesRequest = { resourceId: '' };
exports.ListResourceRulesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        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({}, baseListResourceRulesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListResourceRulesRequest);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.resourceId !== undefined && (obj.resourceId = message.resourceId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseListResourceRulesRequest);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseListResourceRulesResponse = {};
exports.ListResourceRulesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.rules) {
            rule_1.Rule.encode(v, writer.uint32(10).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({}, baseListResourceRulesResponse);
        message.rules = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.rules.push(rule_1.Rule.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseListResourceRulesResponse);
        message.rules = ((_a = object.rules) !== null && _a !== void 0 ? _a : []).map((e) => rule_1.Rule.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.rules) {
            obj.rules = message.rules.map((e) => (e ? rule_1.Rule.toJSON(e) : undefined));
        }
        else {
            obj.rules = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseListResourceRulesResponse);
        message.rules = ((_a = object.rules) === null || _a === void 0 ? void 0 : _a.map((e) => rule_1.Rule.fromPartial(e))) || [];
        return message;
    },
};
const baseCreateResourceRuleRequest = { resourceId: '', name: '', rulePattern: '' };
exports.CreateResourceRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        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({}, baseCreateResourceRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    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({}, baseCreateResourceRuleRequest);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        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.resourceId !== undefined && (obj.resourceId = message.resourceId);
        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({}, baseCreateResourceRuleRequest);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        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;
    },
};
const baseCreateResourceRuleMetadata = { resourceId: '', ruleId: 0 };
exports.CreateResourceRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        if (message.ruleId !== 0) {
            writer.uint32(16).int64(message.ruleId);
        }
        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({}, baseCreateResourceRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    break;
                case 2:
                    message.ruleId = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCreateResourceRuleMetadata);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? Number(object.ruleId) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.resourceId !== undefined && (obj.resourceId = message.resourceId);
        message.ruleId !== undefined && (obj.ruleId = Math.round(message.ruleId));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseCreateResourceRuleMetadata);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        message.ruleId = (_b = object.ruleId) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseGetResourceRuleRequest = { resourceId: '', ruleId: 0 };
exports.GetResourceRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        if (message.ruleId !== 0) {
            writer.uint32(16).int64(message.ruleId);
        }
        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({}, baseGetResourceRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    break;
                case 2:
                    message.ruleId = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetResourceRuleRequest);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? Number(object.ruleId) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.resourceId !== undefined && (obj.resourceId = message.resourceId);
        message.ruleId !== undefined && (obj.ruleId = Math.round(message.ruleId));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseGetResourceRuleRequest);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        message.ruleId = (_b = object.ruleId) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseUpdateResourceRuleRequest = {
    resourceId: '',
    ruleId: 0,
    name: '',
    rulePattern: '',
};
exports.UpdateResourceRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        if (message.ruleId !== 0) {
            writer.uint32(16).int64(message.ruleId);
        }
        if (message.name !== '') {
            writer.uint32(26).string(message.name);
        }
        if (message.rulePattern !== '') {
            writer.uint32(34).string(message.rulePattern);
        }
        if (message.options !== undefined) {
            resource_1.ResourceOptions.encode(message.options, 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({}, baseUpdateResourceRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    break;
                case 2:
                    message.ruleId = longToNumber(reader.int64());
                    break;
                case 3:
                    message.name = reader.string();
                    break;
                case 4:
                    message.rulePattern = reader.string();
                    break;
                case 5:
                    message.options = resource_1.ResourceOptions.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUpdateResourceRuleRequest);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? Number(object.ruleId) : 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.resourceId !== undefined && (obj.resourceId = message.resourceId);
        message.ruleId !== undefined && (obj.ruleId = Math.round(message.ruleId));
        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, _d;
        const message = Object.assign({}, baseUpdateResourceRuleRequest);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        message.ruleId = (_b = object.ruleId) !== null && _b !== void 0 ? _b : 0;
        message.name = (_c = object.name) !== null && _c !== void 0 ? _c : '';
        message.rulePattern = (_d = object.rulePattern) !== null && _d !== void 0 ? _d : '';
        message.options =
            object.options !== undefined && object.options !== null
                ? resource_1.ResourceOptions.fromPartial(object.options)
                : undefined;
        return message;
    },
};
const baseUpdateResourceRuleMetadata = { resourceId: '', ruleId: 0 };
exports.UpdateResourceRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        if (message.ruleId !== 0) {
            writer.uint32(16).int64(message.ruleId);
        }
        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({}, baseUpdateResourceRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    break;
                case 2:
                    message.ruleId = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUpdateResourceRuleMetadata);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? Number(object.ruleId) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.resourceId !== undefined && (obj.resourceId = message.resourceId);
        message.ruleId !== undefined && (obj.ruleId = Math.round(message.ruleId));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseUpdateResourceRuleMetadata);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        message.ruleId = (_b = object.ruleId) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseDeleteResourceRuleRequest = { resourceId: '', ruleId: 0 };
exports.DeleteResourceRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        if (message.ruleId !== 0) {
            writer.uint32(16).int64(message.ruleId);
        }
        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({}, baseDeleteResourceRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    break;
                case 2:
                    message.ruleId = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteResourceRuleRequest);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? Number(object.ruleId) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.resourceId !== undefined && (obj.resourceId = message.resourceId);
        message.ruleId !== undefined && (obj.ruleId = Math.round(message.ruleId));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseDeleteResourceRuleRequest);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        message.ruleId = (_b = object.ruleId) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseDeleteResourceRuleMetadata = { resourceId: '', ruleId: 0 };
exports.DeleteResourceRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resourceId !== '') {
            writer.uint32(10).string(message.resourceId);
        }
        if (message.ruleId !== 0) {
            writer.uint32(16).int64(message.ruleId);
        }
        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({}, baseDeleteResourceRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resourceId = reader.string();
                    break;
                case 2:
                    message.ruleId = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteResourceRuleMetadata);
        message.resourceId =
            object.resourceId !== undefined && object.resourceId !== null
                ? String(object.resourceId)
                : '';
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? Number(object.ruleId) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.resourceId !== undefined && (obj.resourceId = message.resourceId);
        message.ruleId !== undefined && (obj.ruleId = Math.round(message.ruleId));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseDeleteResourceRuleMetadata);
        message.resourceId = (_a = object.resourceId) !== null && _a !== void 0 ? _a : '';
        message.ruleId = (_b = object.ruleId) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
/**
 * Rules management service.
 *
 * Used for Resources Rules management.
 */
exports.ResourceRulesServiceService = {
    /** List all rules for specified resource. */
    list: {
        path: '/yandex.cloud.cdn.v1.ResourceRulesService/List',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListResourceRulesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListResourceRulesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListResourceRulesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListResourceRulesResponse.decode(value),
    },
    /** Create new resource rule with specified unique name and rule patter. */
    create: {
        path: '/yandex.cloud.cdn.v1.ResourceRulesService/Create',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.CreateResourceRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.CreateResourceRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Get specified by id resource rule. */
    get: {
        path: '/yandex.cloud.cdn.v1.ResourceRulesService/Get',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GetResourceRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GetResourceRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(rule_1.Rule.encode(value).finish()),
        responseDeserialize: (value) => rule_1.Rule.decode(value),
    },
    /** Update specified by id resource rule. */
    update: {
        path: '/yandex.cloud.cdn.v1.ResourceRulesService/Update',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.UpdateResourceRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.UpdateResourceRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Delete specified by id resource rule. */
    delete: {
        path: '/yandex.cloud.cdn.v1.ResourceRulesService/Delete',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.DeleteResourceRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.DeleteResourceRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
};
exports.ResourceRulesServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.ResourceRulesServiceService, 'yandex.cloud.cdn.v1.ResourceRulesService');
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();
}
