"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HBARuleServiceClient = exports.HBARuleServiceService = exports.HBARulesMetadata = exports.BatchUpdateHBARulesRequest = exports.ListHBARulesResponse = exports.ListHBARulesAtRevisionRequest = exports.ListHBARulesRequest = exports.DeleteHBARuleRequest = exports.UpdateHBARuleRequest = exports.CreateHBARuleRequest = 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 hba_rule_1 = require("../../../../../yandex/cloud/mdb/greenplum/v1/hba_rule");
const operation_1 = require("../../../../../yandex/cloud/operation/operation");
exports.protobufPackage = 'yandex.cloud.mdb.greenplum.v1';
const baseCreateHBARuleRequest = { clusterId: '' };
exports.CreateHBARuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        if (message.hbaRule !== undefined) {
            hba_rule_1.HBARule.encode(message.hbaRule, writer.uint32(18).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({}, baseCreateHBARuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                case 2:
                    message.hbaRule = hba_rule_1.HBARule.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCreateHBARuleRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.hbaRule =
            object.hbaRule !== undefined && object.hbaRule !== null
                ? hba_rule_1.HBARule.fromJSON(object.hbaRule)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        message.hbaRule !== undefined &&
            (obj.hbaRule = message.hbaRule ? hba_rule_1.HBARule.toJSON(message.hbaRule) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseCreateHBARuleRequest);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        message.hbaRule =
            object.hbaRule !== undefined && object.hbaRule !== null
                ? hba_rule_1.HBARule.fromPartial(object.hbaRule)
                : undefined;
        return message;
    },
};
const baseUpdateHBARuleRequest = { clusterId: '' };
exports.UpdateHBARuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        if (message.hbaRule !== undefined) {
            hba_rule_1.HBARule.encode(message.hbaRule, writer.uint32(18).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({}, baseUpdateHBARuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                case 2:
                    message.hbaRule = hba_rule_1.HBARule.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUpdateHBARuleRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.hbaRule =
            object.hbaRule !== undefined && object.hbaRule !== null
                ? hba_rule_1.HBARule.fromJSON(object.hbaRule)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        message.hbaRule !== undefined &&
            (obj.hbaRule = message.hbaRule ? hba_rule_1.HBARule.toJSON(message.hbaRule) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseUpdateHBARuleRequest);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        message.hbaRule =
            object.hbaRule !== undefined && object.hbaRule !== null
                ? hba_rule_1.HBARule.fromPartial(object.hbaRule)
                : undefined;
        return message;
    },
};
const baseDeleteHBARuleRequest = { clusterId: '', priority: 0 };
exports.DeleteHBARuleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        if (message.priority !== 0) {
            writer.uint32(16).int64(message.priority);
        }
        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({}, baseDeleteHBARuleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                case 2:
                    message.priority = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteHBARuleRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.priority =
            object.priority !== undefined && object.priority !== null ? Number(object.priority) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        message.priority !== undefined && (obj.priority = Math.round(message.priority));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseDeleteHBARuleRequest);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        message.priority = (_b = object.priority) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseListHBARulesRequest = { clusterId: '' };
exports.ListHBARulesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        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({}, baseListHBARulesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListHBARulesRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseListHBARulesRequest);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseListHBARulesAtRevisionRequest = { clusterId: '', revision: 0 };
exports.ListHBARulesAtRevisionRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        if (message.revision !== 0) {
            writer.uint32(16).int64(message.revision);
        }
        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({}, baseListHBARulesAtRevisionRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                case 2:
                    message.revision = longToNumber(reader.int64());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListHBARulesAtRevisionRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.revision =
            object.revision !== undefined && object.revision !== null ? Number(object.revision) : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        message.revision !== undefined && (obj.revision = Math.round(message.revision));
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseListHBARulesAtRevisionRequest);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        message.revision = (_b = object.revision) !== null && _b !== void 0 ? _b : 0;
        return message;
    },
};
const baseListHBARulesResponse = {};
exports.ListHBARulesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.hbaRules) {
            hba_rule_1.HBARule.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({}, baseListHBARulesResponse);
        message.hbaRules = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.hbaRules.push(hba_rule_1.HBARule.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseListHBARulesResponse);
        message.hbaRules = ((_a = object.hbaRules) !== null && _a !== void 0 ? _a : []).map((e) => hba_rule_1.HBARule.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.hbaRules) {
            obj.hbaRules = message.hbaRules.map((e) => (e ? hba_rule_1.HBARule.toJSON(e) : undefined));
        }
        else {
            obj.hbaRules = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseListHBARulesResponse);
        message.hbaRules = ((_a = object.hbaRules) === null || _a === void 0 ? void 0 : _a.map((e) => hba_rule_1.HBARule.fromPartial(e))) || [];
        return message;
    },
};
const baseBatchUpdateHBARulesRequest = { clusterId: '' };
exports.BatchUpdateHBARulesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        for (const v of message.hbaRules) {
            hba_rule_1.HBARule.encode(v, writer.uint32(18).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({}, baseBatchUpdateHBARulesRequest);
        message.hbaRules = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                case 2:
                    message.hbaRules.push(hba_rule_1.HBARule.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseBatchUpdateHBARulesRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.hbaRules = ((_a = object.hbaRules) !== null && _a !== void 0 ? _a : []).map((e) => hba_rule_1.HBARule.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        if (message.hbaRules) {
            obj.hbaRules = message.hbaRules.map((e) => (e ? hba_rule_1.HBARule.toJSON(e) : undefined));
        }
        else {
            obj.hbaRules = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseBatchUpdateHBARulesRequest);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        message.hbaRules = ((_b = object.hbaRules) === null || _b === void 0 ? void 0 : _b.map((e) => hba_rule_1.HBARule.fromPartial(e))) || [];
        return message;
    },
};
const baseHBARulesMetadata = { clusterId: '' };
exports.HBARulesMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        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({}, baseHBARulesMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseHBARulesMetadata);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseHBARulesMetadata);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
/** A set of methods for managing Greenplum clusters. */
exports.HBARuleServiceService = {
    /** Retrieves a list of HBA rules for Greenplum clusters. */
    list: {
        path: '/yandex.cloud.mdb.greenplum.v1.HBARuleService/List',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListHBARulesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListHBARulesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListHBARulesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListHBARulesResponse.decode(value),
    },
    /** Retrieves a list of HBA rules for Greenplum clusters for particular revision. */
    listAtRevision: {
        path: '/yandex.cloud.mdb.greenplum.v1.HBARuleService/ListAtRevision',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListHBARulesAtRevisionRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListHBARulesAtRevisionRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListHBARulesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListHBARulesResponse.decode(value),
    },
    /** Create single HBA rule for the specified Greenplum cluster to the end of HBA rules list. */
    create: {
        path: '/yandex.cloud.mdb.greenplum.v1.HBARuleService/Create',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.CreateHBARuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.CreateHBARuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Update specified HBA rule for the specified Greenplum cluster without changind it order. */
    update: {
        path: '/yandex.cloud.mdb.greenplum.v1.HBARuleService/Update',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.UpdateHBARuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.UpdateHBARuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Delete specified HBA rule for the specified Greenplum cluster. */
    delete: {
        path: '/yandex.cloud.mdb.greenplum.v1.HBARuleService/Delete',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.DeleteHBARuleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.DeleteHBARuleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Modifies all HBA rules for the specified Greenplum cluster. */
    batchUpdate: {
        path: '/yandex.cloud.mdb.greenplum.v1.HBARuleService/BatchUpdate',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.BatchUpdateHBARulesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.BatchUpdateHBARulesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
};
exports.HBARuleServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.HBARuleServiceService, 'yandex.cloud.mdb.greenplum.v1.HBARuleService');
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();
}
