"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleServiceClient = exports.RuleServiceService = exports.DisableRuleMetadata = exports.DisableRuleRequest = exports.EnableRuleMetadata = exports.EnableRuleRequest = exports.ListRuleOperationsResponse = exports.ListRuleOperationsRequest = exports.DeleteRuleMetadata = exports.DeleteRuleRequest = exports.UpdateRuleMetadata = exports.UpdateRuleRequest_LabelsEntry = exports.UpdateRuleRequest = exports.CreateRuleMetadata = exports.CreateRuleRequest_LabelsEntry = exports.CreateRuleRequest = exports.ListRulesResponse = exports.ListRulesRequest = exports.GetRuleRequest = 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 rule_1 = require("../../../../../yandex/cloud/serverless/eventrouter/v1/rule");
const field_mask_1 = require("../../../../../google/protobuf/field_mask");
const operation_1 = require("../../../../../yandex/cloud/operation/operation");
const access_1 = require("../../../../../yandex/cloud/access/access");
exports.protobufPackage = 'yandex.cloud.serverless.eventrouter.v1';
const baseGetRuleRequest = { ruleId: '' };
exports.GetRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseGetRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetRuleRequest);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGetRuleRequest);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseListRulesRequest = { pageSize: 0, pageToken: '', filter: '' };
exports.ListRulesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.busId !== undefined) {
            writer.uint32(10).string(message.busId);
        }
        if (message.folderId !== undefined) {
            writer.uint32(18).string(message.folderId);
        }
        if (message.pageSize !== 0) {
            writer.uint32(24).int64(message.pageSize);
        }
        if (message.pageToken !== '') {
            writer.uint32(34).string(message.pageToken);
        }
        if (message.filter !== '') {
            writer.uint32(42).string(message.filter);
        }
        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({}, baseListRulesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.busId = reader.string();
                    break;
                case 2:
                    message.folderId = reader.string();
                    break;
                case 3:
                    message.pageSize = longToNumber(reader.int64());
                    break;
                case 4:
                    message.pageToken = reader.string();
                    break;
                case 5:
                    message.filter = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListRulesRequest);
        message.busId =
            object.busId !== undefined && object.busId !== null ? String(object.busId) : undefined;
        message.folderId =
            object.folderId !== undefined && object.folderId !== null
                ? String(object.folderId)
                : undefined;
        message.pageSize =
            object.pageSize !== undefined && object.pageSize !== null ? Number(object.pageSize) : 0;
        message.pageToken =
            object.pageToken !== undefined && object.pageToken !== null
                ? String(object.pageToken)
                : '';
        message.filter =
            object.filter !== undefined && object.filter !== null ? String(object.filter) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.busId !== undefined && (obj.busId = message.busId);
        message.folderId !== undefined && (obj.folderId = message.folderId);
        message.pageSize !== undefined && (obj.pageSize = Math.round(message.pageSize));
        message.pageToken !== undefined && (obj.pageToken = message.pageToken);
        message.filter !== undefined && (obj.filter = message.filter);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e;
        const message = Object.assign({}, baseListRulesRequest);
        message.busId = (_a = object.busId) !== null && _a !== void 0 ? _a : undefined;
        message.folderId = (_b = object.folderId) !== null && _b !== void 0 ? _b : undefined;
        message.pageSize = (_c = object.pageSize) !== null && _c !== void 0 ? _c : 0;
        message.pageToken = (_d = object.pageToken) !== null && _d !== void 0 ? _d : '';
        message.filter = (_e = object.filter) !== null && _e !== void 0 ? _e : '';
        return message;
    },
};
const baseListRulesResponse = { nextPageToken: '' };
exports.ListRulesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.rules) {
            rule_1.Rule.encode(v, writer.uint32(10).fork()).ldelim();
        }
        if (message.nextPageToken !== '') {
            writer.uint32(18).string(message.nextPageToken);
        }
        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({}, baseListRulesResponse);
        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;
                case 2:
                    message.nextPageToken = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseListRulesResponse);
        message.rules = ((_a = object.rules) !== null && _a !== void 0 ? _a : []).map((e) => rule_1.Rule.fromJSON(e));
        message.nextPageToken =
            object.nextPageToken !== undefined && object.nextPageToken !== null
                ? String(object.nextPageToken)
                : '';
        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 = [];
        }
        message.nextPageToken !== undefined && (obj.nextPageToken = message.nextPageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseListRulesResponse);
        message.rules = ((_a = object.rules) === null || _a === void 0 ? void 0 : _a.map((e) => rule_1.Rule.fromPartial(e))) || [];
        message.nextPageToken = (_b = object.nextPageToken) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseCreateRuleRequest = {
    busId: '',
    name: '',
    description: '',
    deletionProtection: false,
};
exports.CreateRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.busId !== '') {
            writer.uint32(10).string(message.busId);
        }
        if (message.name !== '') {
            writer.uint32(18).string(message.name);
        }
        if (message.description !== '') {
            writer.uint32(26).string(message.description);
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.CreateRuleRequest_LabelsEntry.encode({ key: key, value }, writer.uint32(34).fork()).ldelim();
        });
        if (message.filter !== undefined) {
            rule_1.Filter.encode(message.filter, writer.uint32(42).fork()).ldelim();
        }
        for (const v of message.targets) {
            rule_1.Target.encode(v, writer.uint32(50).fork()).ldelim();
        }
        if (message.deletionProtection === true) {
            writer.uint32(56).bool(message.deletionProtection);
        }
        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({}, baseCreateRuleRequest);
        message.labels = {};
        message.targets = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.busId = reader.string();
                    break;
                case 2:
                    message.name = reader.string();
                    break;
                case 3:
                    message.description = reader.string();
                    break;
                case 4:
                    const entry4 = exports.CreateRuleRequest_LabelsEntry.decode(reader, reader.uint32());
                    if (entry4.value !== undefined) {
                        message.labels[entry4.key] = entry4.value;
                    }
                    break;
                case 5:
                    message.filter = rule_1.Filter.decode(reader, reader.uint32());
                    break;
                case 6:
                    message.targets.push(rule_1.Target.decode(reader, reader.uint32()));
                    break;
                case 7:
                    message.deletionProtection = reader.bool();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseCreateRuleRequest);
        message.busId =
            object.busId !== undefined && object.busId !== null ? String(object.busId) : '';
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.labels = Object.entries((_a = object.labels) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.filter =
            object.filter !== undefined && object.filter !== null
                ? rule_1.Filter.fromJSON(object.filter)
                : undefined;
        message.targets = ((_b = object.targets) !== null && _b !== void 0 ? _b : []).map((e) => rule_1.Target.fromJSON(e));
        message.deletionProtection =
            object.deletionProtection !== undefined && object.deletionProtection !== null
                ? Boolean(object.deletionProtection)
                : false;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.busId !== undefined && (obj.busId = message.busId);
        message.name !== undefined && (obj.name = message.name);
        message.description !== undefined && (obj.description = message.description);
        obj.labels = {};
        if (message.labels) {
            Object.entries(message.labels).forEach(([k, v]) => {
                obj.labels[k] = v;
            });
        }
        message.filter !== undefined &&
            (obj.filter = message.filter ? rule_1.Filter.toJSON(message.filter) : undefined);
        if (message.targets) {
            obj.targets = message.targets.map((e) => (e ? rule_1.Target.toJSON(e) : undefined));
        }
        else {
            obj.targets = [];
        }
        message.deletionProtection !== undefined &&
            (obj.deletionProtection = message.deletionProtection);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f;
        const message = Object.assign({}, baseCreateRuleRequest);
        message.busId = (_a = object.busId) !== null && _a !== void 0 ? _a : '';
        message.name = (_b = object.name) !== null && _b !== void 0 ? _b : '';
        message.description = (_c = object.description) !== null && _c !== void 0 ? _c : '';
        message.labels = Object.entries((_d = object.labels) !== null && _d !== void 0 ? _d : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.filter =
            object.filter !== undefined && object.filter !== null
                ? rule_1.Filter.fromPartial(object.filter)
                : undefined;
        message.targets = ((_e = object.targets) === null || _e === void 0 ? void 0 : _e.map((e) => rule_1.Target.fromPartial(e))) || [];
        message.deletionProtection = (_f = object.deletionProtection) !== null && _f !== void 0 ? _f : false;
        return message;
    },
};
const baseCreateRuleRequest_LabelsEntry = { key: '', value: '' };
exports.CreateRuleRequest_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({}, baseCreateRuleRequest_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({}, baseCreateRuleRequest_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({}, baseCreateRuleRequest_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseCreateRuleMetadata = { ruleId: '', busId: '' };
exports.CreateRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(message.ruleId);
        }
        if (message.busId !== '') {
            writer.uint32(18).string(message.busId);
        }
        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({}, baseCreateRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                case 2:
                    message.busId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCreateRuleMetadata);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        message.busId =
            object.busId !== undefined && object.busId !== null ? String(object.busId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        message.busId !== undefined && (obj.busId = message.busId);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseCreateRuleMetadata);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        message.busId = (_b = object.busId) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseUpdateRuleRequest = {
    ruleId: '',
    name: '',
    description: '',
    deletionProtection: false,
};
exports.UpdateRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(message.ruleId);
        }
        if (message.updateMask !== undefined) {
            field_mask_1.FieldMask.encode(message.updateMask, writer.uint32(18).fork()).ldelim();
        }
        if (message.name !== '') {
            writer.uint32(26).string(message.name);
        }
        if (message.description !== '') {
            writer.uint32(34).string(message.description);
        }
        Object.entries(message.labels).forEach(([key, value]) => {
            exports.UpdateRuleRequest_LabelsEntry.encode({ key: key, value }, writer.uint32(42).fork()).ldelim();
        });
        if (message.filter !== undefined) {
            rule_1.Filter.encode(message.filter, writer.uint32(50).fork()).ldelim();
        }
        for (const v of message.targets) {
            rule_1.Target.encode(v, writer.uint32(58).fork()).ldelim();
        }
        if (message.deletionProtection === true) {
            writer.uint32(64).bool(message.deletionProtection);
        }
        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({}, baseUpdateRuleRequest);
        message.labels = {};
        message.targets = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                case 2:
                    message.updateMask = field_mask_1.FieldMask.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.name = reader.string();
                    break;
                case 4:
                    message.description = reader.string();
                    break;
                case 5:
                    const entry5 = exports.UpdateRuleRequest_LabelsEntry.decode(reader, reader.uint32());
                    if (entry5.value !== undefined) {
                        message.labels[entry5.key] = entry5.value;
                    }
                    break;
                case 6:
                    message.filter = rule_1.Filter.decode(reader, reader.uint32());
                    break;
                case 7:
                    message.targets.push(rule_1.Target.decode(reader, reader.uint32()));
                    break;
                case 8:
                    message.deletionProtection = reader.bool();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseUpdateRuleRequest);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        message.updateMask =
            object.updateMask !== undefined && object.updateMask !== null
                ? field_mask_1.FieldMask.fromJSON(object.updateMask)
                : undefined;
        message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.labels = Object.entries((_a = object.labels) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.filter =
            object.filter !== undefined && object.filter !== null
                ? rule_1.Filter.fromJSON(object.filter)
                : undefined;
        message.targets = ((_b = object.targets) !== null && _b !== void 0 ? _b : []).map((e) => rule_1.Target.fromJSON(e));
        message.deletionProtection =
            object.deletionProtection !== undefined && object.deletionProtection !== null
                ? Boolean(object.deletionProtection)
                : false;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        message.updateMask !== undefined &&
            (obj.updateMask = message.updateMask
                ? field_mask_1.FieldMask.toJSON(message.updateMask)
                : undefined);
        message.name !== undefined && (obj.name = message.name);
        message.description !== undefined && (obj.description = message.description);
        obj.labels = {};
        if (message.labels) {
            Object.entries(message.labels).forEach(([k, v]) => {
                obj.labels[k] = v;
            });
        }
        message.filter !== undefined &&
            (obj.filter = message.filter ? rule_1.Filter.toJSON(message.filter) : undefined);
        if (message.targets) {
            obj.targets = message.targets.map((e) => (e ? rule_1.Target.toJSON(e) : undefined));
        }
        else {
            obj.targets = [];
        }
        message.deletionProtection !== undefined &&
            (obj.deletionProtection = message.deletionProtection);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f;
        const message = Object.assign({}, baseUpdateRuleRequest);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        message.updateMask =
            object.updateMask !== undefined && object.updateMask !== null
                ? field_mask_1.FieldMask.fromPartial(object.updateMask)
                : undefined;
        message.name = (_b = object.name) !== null && _b !== void 0 ? _b : '';
        message.description = (_c = object.description) !== null && _c !== void 0 ? _c : '';
        message.labels = Object.entries((_d = object.labels) !== null && _d !== void 0 ? _d : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.filter =
            object.filter !== undefined && object.filter !== null
                ? rule_1.Filter.fromPartial(object.filter)
                : undefined;
        message.targets = ((_e = object.targets) === null || _e === void 0 ? void 0 : _e.map((e) => rule_1.Target.fromPartial(e))) || [];
        message.deletionProtection = (_f = object.deletionProtection) !== null && _f !== void 0 ? _f : false;
        return message;
    },
};
const baseUpdateRuleRequest_LabelsEntry = { key: '', value: '' };
exports.UpdateRuleRequest_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({}, baseUpdateRuleRequest_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({}, baseUpdateRuleRequest_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({}, baseUpdateRuleRequest_LabelsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseUpdateRuleMetadata = { ruleId: '' };
exports.UpdateRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseUpdateRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUpdateRuleMetadata);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseUpdateRuleMetadata);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseDeleteRuleRequest = { ruleId: '' };
exports.DeleteRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseDeleteRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteRuleRequest);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDeleteRuleRequest);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseDeleteRuleMetadata = { ruleId: '' };
exports.DeleteRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseDeleteRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteRuleMetadata);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDeleteRuleMetadata);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseListRuleOperationsRequest = {
    ruleId: '',
    pageSize: 0,
    pageToken: '',
    filter: '',
};
exports.ListRuleOperationsRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(message.ruleId);
        }
        if (message.pageSize !== 0) {
            writer.uint32(16).int64(message.pageSize);
        }
        if (message.pageToken !== '') {
            writer.uint32(26).string(message.pageToken);
        }
        if (message.filter !== '') {
            writer.uint32(34).string(message.filter);
        }
        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({}, baseListRuleOperationsRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                case 2:
                    message.pageSize = longToNumber(reader.int64());
                    break;
                case 3:
                    message.pageToken = reader.string();
                    break;
                case 4:
                    message.filter = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListRuleOperationsRequest);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        message.pageSize =
            object.pageSize !== undefined && object.pageSize !== null ? Number(object.pageSize) : 0;
        message.pageToken =
            object.pageToken !== undefined && object.pageToken !== null
                ? String(object.pageToken)
                : '';
        message.filter =
            object.filter !== undefined && object.filter !== null ? String(object.filter) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        message.pageSize !== undefined && (obj.pageSize = Math.round(message.pageSize));
        message.pageToken !== undefined && (obj.pageToken = message.pageToken);
        message.filter !== undefined && (obj.filter = message.filter);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = Object.assign({}, baseListRuleOperationsRequest);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        message.pageSize = (_b = object.pageSize) !== null && _b !== void 0 ? _b : 0;
        message.pageToken = (_c = object.pageToken) !== null && _c !== void 0 ? _c : '';
        message.filter = (_d = object.filter) !== null && _d !== void 0 ? _d : '';
        return message;
    },
};
const baseListRuleOperationsResponse = { nextPageToken: '' };
exports.ListRuleOperationsResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.operations) {
            operation_1.Operation.encode(v, writer.uint32(10).fork()).ldelim();
        }
        if (message.nextPageToken !== '') {
            writer.uint32(18).string(message.nextPageToken);
        }
        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({}, baseListRuleOperationsResponse);
        message.operations = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.operations.push(operation_1.Operation.decode(reader, reader.uint32()));
                    break;
                case 2:
                    message.nextPageToken = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseListRuleOperationsResponse);
        message.operations = ((_a = object.operations) !== null && _a !== void 0 ? _a : []).map((e) => operation_1.Operation.fromJSON(e));
        message.nextPageToken =
            object.nextPageToken !== undefined && object.nextPageToken !== null
                ? String(object.nextPageToken)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.operations) {
            obj.operations = message.operations.map((e) => (e ? operation_1.Operation.toJSON(e) : undefined));
        }
        else {
            obj.operations = [];
        }
        message.nextPageToken !== undefined && (obj.nextPageToken = message.nextPageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseListRuleOperationsResponse);
        message.operations = ((_a = object.operations) === null || _a === void 0 ? void 0 : _a.map((e) => operation_1.Operation.fromPartial(e))) || [];
        message.nextPageToken = (_b = object.nextPageToken) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseEnableRuleRequest = { ruleId: '' };
exports.EnableRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseEnableRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseEnableRuleRequest);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseEnableRuleRequest);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseEnableRuleMetadata = { ruleId: '' };
exports.EnableRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseEnableRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseEnableRuleMetadata);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseEnableRuleMetadata);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseDisableRuleRequest = { ruleId: '' };
exports.DisableRuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseDisableRuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDisableRuleRequest);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDisableRuleRequest);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseDisableRuleMetadata = { ruleId: '' };
exports.DisableRuleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.ruleId !== '') {
            writer.uint32(10).string(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({}, baseDisableRuleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ruleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDisableRuleMetadata);
        message.ruleId =
            object.ruleId !== undefined && object.ruleId !== null ? String(object.ruleId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.ruleId !== undefined && (obj.ruleId = message.ruleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDisableRuleMetadata);
        message.ruleId = (_a = object.ruleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
/** A set of methods for managing rules for serverless eventrouter. */
exports.RuleServiceService = {
    /**
     * Returns the specified rules.
     * To get the list of all available buses, make a [List] request.
     */
    get: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/Get',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GetRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GetRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(rule_1.Rule.encode(value).finish()),
        responseDeserialize: (value) => rule_1.Rule.decode(value),
    },
    /** Retrieves the list of rules in the specified folder. */
    list: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/List',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListRulesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListRulesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListRulesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListRulesResponse.decode(value),
    },
    /** Creates a rule in the specified folder. */
    create: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/Create',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.CreateRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.CreateRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Updates the specified rule. */
    update: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/Update',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.UpdateRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.UpdateRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Deletes the specified rule. */
    delete: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/Delete',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.DeleteRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.DeleteRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Enables the specified rule. */
    enable: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/Enable',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.EnableRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.EnableRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Disables the specified rule. */
    disable: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/Disable',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.DisableRuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.DisableRuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Lists existing access bindings for the specified rule. */
    listAccessBindings: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/ListAccessBindings',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(access_1.ListAccessBindingsRequest.encode(value).finish()),
        requestDeserialize: (value) => access_1.ListAccessBindingsRequest.decode(value),
        responseSerialize: (value) => Buffer.from(access_1.ListAccessBindingsResponse.encode(value).finish()),
        responseDeserialize: (value) => access_1.ListAccessBindingsResponse.decode(value),
    },
    /** Sets access bindings for the rule. */
    setAccessBindings: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/SetAccessBindings',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(access_1.SetAccessBindingsRequest.encode(value).finish()),
        requestDeserialize: (value) => access_1.SetAccessBindingsRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Updates access bindings for the specified rule. */
    updateAccessBindings: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/UpdateAccessBindings',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(access_1.UpdateAccessBindingsRequest.encode(value).finish()),
        requestDeserialize: (value) => access_1.UpdateAccessBindingsRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Lists operations for the specified rule. */
    listOperations: {
        path: '/yandex.cloud.serverless.eventrouter.v1.RuleService/ListOperations',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListRuleOperationsRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListRuleOperationsRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListRuleOperationsResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListRuleOperationsResponse.decode(value),
    },
};
exports.RuleServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.RuleServiceService, 'yandex.cloud.serverless.eventrouter.v1.RuleService');
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();
}
