"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostgresTarget = exports.PostgresSource = exports.PostgresConnection = exports.OnPremisePostgres = exports.PostgresObjectTransferSettings = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const common_1 = require("../../../../../yandex/cloud/datatransfer/v1/endpoint/common");
exports.protobufPackage = 'yandex.cloud.datatransfer.v1.endpoint';
const basePostgresObjectTransferSettings = {
    sequence: 0,
    sequenceOwnedBy: 0,
    table: 0,
    primaryKey: 0,
    fkConstraint: 0,
    defaultValues: 0,
    constraint: 0,
    index: 0,
    view: 0,
    function: 0,
    trigger: 0,
    type: 0,
    rule: 0,
    collation: 0,
    policy: 0,
    cast: 0,
    materializedView: 0,
    sequenceSet: 0,
};
exports.PostgresObjectTransferSettings = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.sequence !== 0) {
            writer.uint32(8).int32(message.sequence);
        }
        if (message.sequenceOwnedBy !== 0) {
            writer.uint32(16).int32(message.sequenceOwnedBy);
        }
        if (message.table !== 0) {
            writer.uint32(24).int32(message.table);
        }
        if (message.primaryKey !== 0) {
            writer.uint32(32).int32(message.primaryKey);
        }
        if (message.fkConstraint !== 0) {
            writer.uint32(40).int32(message.fkConstraint);
        }
        if (message.defaultValues !== 0) {
            writer.uint32(48).int32(message.defaultValues);
        }
        if (message.constraint !== 0) {
            writer.uint32(56).int32(message.constraint);
        }
        if (message.index !== 0) {
            writer.uint32(64).int32(message.index);
        }
        if (message.view !== 0) {
            writer.uint32(72).int32(message.view);
        }
        if (message.function !== 0) {
            writer.uint32(80).int32(message.function);
        }
        if (message.trigger !== 0) {
            writer.uint32(88).int32(message.trigger);
        }
        if (message.type !== 0) {
            writer.uint32(96).int32(message.type);
        }
        if (message.rule !== 0) {
            writer.uint32(104).int32(message.rule);
        }
        if (message.collation !== 0) {
            writer.uint32(112).int32(message.collation);
        }
        if (message.policy !== 0) {
            writer.uint32(120).int32(message.policy);
        }
        if (message.cast !== 0) {
            writer.uint32(128).int32(message.cast);
        }
        if (message.materializedView !== 0) {
            writer.uint32(136).int32(message.materializedView);
        }
        if (message.sequenceSet !== 0) {
            writer.uint32(144).int32(message.sequenceSet);
        }
        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({}, basePostgresObjectTransferSettings);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.sequence = reader.int32();
                    break;
                case 2:
                    message.sequenceOwnedBy = reader.int32();
                    break;
                case 3:
                    message.table = reader.int32();
                    break;
                case 4:
                    message.primaryKey = reader.int32();
                    break;
                case 5:
                    message.fkConstraint = reader.int32();
                    break;
                case 6:
                    message.defaultValues = reader.int32();
                    break;
                case 7:
                    message.constraint = reader.int32();
                    break;
                case 8:
                    message.index = reader.int32();
                    break;
                case 9:
                    message.view = reader.int32();
                    break;
                case 10:
                    message.function = reader.int32();
                    break;
                case 11:
                    message.trigger = reader.int32();
                    break;
                case 12:
                    message.type = reader.int32();
                    break;
                case 13:
                    message.rule = reader.int32();
                    break;
                case 14:
                    message.collation = reader.int32();
                    break;
                case 15:
                    message.policy = reader.int32();
                    break;
                case 16:
                    message.cast = reader.int32();
                    break;
                case 17:
                    message.materializedView = reader.int32();
                    break;
                case 18:
                    message.sequenceSet = reader.int32();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, basePostgresObjectTransferSettings);
        message.sequence =
            object.sequence !== undefined && object.sequence !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.sequence)
                : 0;
        message.sequenceOwnedBy =
            object.sequenceOwnedBy !== undefined && object.sequenceOwnedBy !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.sequenceOwnedBy)
                : 0;
        message.table =
            object.table !== undefined && object.table !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.table)
                : 0;
        message.primaryKey =
            object.primaryKey !== undefined && object.primaryKey !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.primaryKey)
                : 0;
        message.fkConstraint =
            object.fkConstraint !== undefined && object.fkConstraint !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.fkConstraint)
                : 0;
        message.defaultValues =
            object.defaultValues !== undefined && object.defaultValues !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.defaultValues)
                : 0;
        message.constraint =
            object.constraint !== undefined && object.constraint !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.constraint)
                : 0;
        message.index =
            object.index !== undefined && object.index !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.index)
                : 0;
        message.view =
            object.view !== undefined && object.view !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.view)
                : 0;
        message.function =
            object.function !== undefined && object.function !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.function)
                : 0;
        message.trigger =
            object.trigger !== undefined && object.trigger !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.trigger)
                : 0;
        message.type =
            object.type !== undefined && object.type !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.type)
                : 0;
        message.rule =
            object.rule !== undefined && object.rule !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.rule)
                : 0;
        message.collation =
            object.collation !== undefined && object.collation !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.collation)
                : 0;
        message.policy =
            object.policy !== undefined && object.policy !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.policy)
                : 0;
        message.cast =
            object.cast !== undefined && object.cast !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.cast)
                : 0;
        message.materializedView =
            object.materializedView !== undefined && object.materializedView !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.materializedView)
                : 0;
        message.sequenceSet =
            object.sequenceSet !== undefined && object.sequenceSet !== null
                ? (0, common_1.objectTransferStageFromJSON)(object.sequenceSet)
                : 0;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.sequence !== undefined &&
            (obj.sequence = (0, common_1.objectTransferStageToJSON)(message.sequence));
        message.sequenceOwnedBy !== undefined &&
            (obj.sequenceOwnedBy = (0, common_1.objectTransferStageToJSON)(message.sequenceOwnedBy));
        message.table !== undefined && (obj.table = (0, common_1.objectTransferStageToJSON)(message.table));
        message.primaryKey !== undefined &&
            (obj.primaryKey = (0, common_1.objectTransferStageToJSON)(message.primaryKey));
        message.fkConstraint !== undefined &&
            (obj.fkConstraint = (0, common_1.objectTransferStageToJSON)(message.fkConstraint));
        message.defaultValues !== undefined &&
            (obj.defaultValues = (0, common_1.objectTransferStageToJSON)(message.defaultValues));
        message.constraint !== undefined &&
            (obj.constraint = (0, common_1.objectTransferStageToJSON)(message.constraint));
        message.index !== undefined && (obj.index = (0, common_1.objectTransferStageToJSON)(message.index));
        message.view !== undefined && (obj.view = (0, common_1.objectTransferStageToJSON)(message.view));
        message.function !== undefined &&
            (obj.function = (0, common_1.objectTransferStageToJSON)(message.function));
        message.trigger !== undefined && (obj.trigger = (0, common_1.objectTransferStageToJSON)(message.trigger));
        message.type !== undefined && (obj.type = (0, common_1.objectTransferStageToJSON)(message.type));
        message.rule !== undefined && (obj.rule = (0, common_1.objectTransferStageToJSON)(message.rule));
        message.collation !== undefined &&
            (obj.collation = (0, common_1.objectTransferStageToJSON)(message.collation));
        message.policy !== undefined && (obj.policy = (0, common_1.objectTransferStageToJSON)(message.policy));
        message.cast !== undefined && (obj.cast = (0, common_1.objectTransferStageToJSON)(message.cast));
        message.materializedView !== undefined &&
            (obj.materializedView = (0, common_1.objectTransferStageToJSON)(message.materializedView));
        message.sequenceSet !== undefined &&
            (obj.sequenceSet = (0, common_1.objectTransferStageToJSON)(message.sequenceSet));
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
        const message = Object.assign({}, basePostgresObjectTransferSettings);
        message.sequence = (_a = object.sequence) !== null && _a !== void 0 ? _a : 0;
        message.sequenceOwnedBy = (_b = object.sequenceOwnedBy) !== null && _b !== void 0 ? _b : 0;
        message.table = (_c = object.table) !== null && _c !== void 0 ? _c : 0;
        message.primaryKey = (_d = object.primaryKey) !== null && _d !== void 0 ? _d : 0;
        message.fkConstraint = (_e = object.fkConstraint) !== null && _e !== void 0 ? _e : 0;
        message.defaultValues = (_f = object.defaultValues) !== null && _f !== void 0 ? _f : 0;
        message.constraint = (_g = object.constraint) !== null && _g !== void 0 ? _g : 0;
        message.index = (_h = object.index) !== null && _h !== void 0 ? _h : 0;
        message.view = (_j = object.view) !== null && _j !== void 0 ? _j : 0;
        message.function = (_k = object.function) !== null && _k !== void 0 ? _k : 0;
        message.trigger = (_l = object.trigger) !== null && _l !== void 0 ? _l : 0;
        message.type = (_m = object.type) !== null && _m !== void 0 ? _m : 0;
        message.rule = (_o = object.rule) !== null && _o !== void 0 ? _o : 0;
        message.collation = (_p = object.collation) !== null && _p !== void 0 ? _p : 0;
        message.policy = (_q = object.policy) !== null && _q !== void 0 ? _q : 0;
        message.cast = (_r = object.cast) !== null && _r !== void 0 ? _r : 0;
        message.materializedView = (_s = object.materializedView) !== null && _s !== void 0 ? _s : 0;
        message.sequenceSet = (_t = object.sequenceSet) !== null && _t !== void 0 ? _t : 0;
        return message;
    },
};
const baseOnPremisePostgres = { port: 0, subnetId: '', hosts: '' };
exports.OnPremisePostgres = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.port !== 0) {
            writer.uint32(16).int64(message.port);
        }
        if (message.subnetId !== '') {
            writer.uint32(34).string(message.subnetId);
        }
        for (const v of message.hosts) {
            writer.uint32(42).string(v);
        }
        if (message.tlsMode !== undefined) {
            common_1.TLSMode.encode(message.tlsMode, writer.uint32(50).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseOnPremisePostgres);
        message.hosts = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 2:
                    message.port = longToNumber(reader.int64());
                    break;
                case 4:
                    message.subnetId = reader.string();
                    break;
                case 5:
                    message.hosts.push(reader.string());
                    break;
                case 6:
                    message.tlsMode = common_1.TLSMode.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseOnPremisePostgres);
        message.port = object.port !== undefined && object.port !== null ? Number(object.port) : 0;
        message.subnetId =
            object.subnetId !== undefined && object.subnetId !== null
                ? String(object.subnetId)
                : '';
        message.hosts = ((_a = object.hosts) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
        message.tlsMode =
            object.tlsMode !== undefined && object.tlsMode !== null
                ? common_1.TLSMode.fromJSON(object.tlsMode)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.port !== undefined && (obj.port = Math.round(message.port));
        message.subnetId !== undefined && (obj.subnetId = message.subnetId);
        if (message.hosts) {
            obj.hosts = message.hosts.map((e) => e);
        }
        else {
            obj.hosts = [];
        }
        message.tlsMode !== undefined &&
            (obj.tlsMode = message.tlsMode ? common_1.TLSMode.toJSON(message.tlsMode) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseOnPremisePostgres);
        message.port = (_a = object.port) !== null && _a !== void 0 ? _a : 0;
        message.subnetId = (_b = object.subnetId) !== null && _b !== void 0 ? _b : '';
        message.hosts = ((_c = object.hosts) === null || _c === void 0 ? void 0 : _c.map((e) => e)) || [];
        message.tlsMode =
            object.tlsMode !== undefined && object.tlsMode !== null
                ? common_1.TLSMode.fromPartial(object.tlsMode)
                : undefined;
        return message;
    },
};
const basePostgresConnection = {};
exports.PostgresConnection = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.mdbClusterId !== undefined) {
            writer.uint32(10).string(message.mdbClusterId);
        }
        if (message.onPremise !== undefined) {
            exports.OnPremisePostgres.encode(message.onPremise, writer.uint32(18).fork()).ldelim();
        }
        if (message.connectionManagerConnection !== undefined) {
            common_1.ConnectionManagerConnection.encode(message.connectionManagerConnection, writer.uint32(26).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({}, basePostgresConnection);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.mdbClusterId = reader.string();
                    break;
                case 2:
                    message.onPremise = exports.OnPremisePostgres.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.connectionManagerConnection = common_1.ConnectionManagerConnection.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, basePostgresConnection);
        message.mdbClusterId =
            object.mdbClusterId !== undefined && object.mdbClusterId !== null
                ? String(object.mdbClusterId)
                : undefined;
        message.onPremise =
            object.onPremise !== undefined && object.onPremise !== null
                ? exports.OnPremisePostgres.fromJSON(object.onPremise)
                : undefined;
        message.connectionManagerConnection =
            object.connectionManagerConnection !== undefined &&
                object.connectionManagerConnection !== null
                ? common_1.ConnectionManagerConnection.fromJSON(object.connectionManagerConnection)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.mdbClusterId !== undefined && (obj.mdbClusterId = message.mdbClusterId);
        message.onPremise !== undefined &&
            (obj.onPremise = message.onPremise
                ? exports.OnPremisePostgres.toJSON(message.onPremise)
                : undefined);
        message.connectionManagerConnection !== undefined &&
            (obj.connectionManagerConnection = message.connectionManagerConnection
                ? common_1.ConnectionManagerConnection.toJSON(message.connectionManagerConnection)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, basePostgresConnection);
        message.mdbClusterId = (_a = object.mdbClusterId) !== null && _a !== void 0 ? _a : undefined;
        message.onPremise =
            object.onPremise !== undefined && object.onPremise !== null
                ? exports.OnPremisePostgres.fromPartial(object.onPremise)
                : undefined;
        message.connectionManagerConnection =
            object.connectionManagerConnection !== undefined &&
                object.connectionManagerConnection !== null
                ? common_1.ConnectionManagerConnection.fromPartial(object.connectionManagerConnection)
                : undefined;
        return message;
    },
};
const basePostgresSource = {
    database: '',
    user: '',
    includeTables: '',
    excludeTables: '',
    slotByteLagLimit: 0,
    serviceSchema: '',
    securityGroups: '',
};
exports.PostgresSource = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.connection !== undefined) {
            exports.PostgresConnection.encode(message.connection, writer.uint32(10).fork()).ldelim();
        }
        if (message.database !== '') {
            writer.uint32(18).string(message.database);
        }
        if (message.user !== '') {
            writer.uint32(26).string(message.user);
        }
        if (message.password !== undefined) {
            common_1.Secret.encode(message.password, writer.uint32(34).fork()).ldelim();
        }
        for (const v of message.includeTables) {
            writer.uint32(42).string(v);
        }
        for (const v of message.excludeTables) {
            writer.uint32(50).string(v);
        }
        if (message.slotByteLagLimit !== 0) {
            writer.uint32(64).int64(message.slotByteLagLimit);
        }
        if (message.serviceSchema !== '') {
            writer.uint32(74).string(message.serviceSchema);
        }
        if (message.objectTransferSettings !== undefined) {
            exports.PostgresObjectTransferSettings.encode(message.objectTransferSettings, writer.uint32(106).fork()).ldelim();
        }
        for (const v of message.securityGroups) {
            writer.uint32(114).string(v);
        }
        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({}, basePostgresSource);
        message.includeTables = [];
        message.excludeTables = [];
        message.securityGroups = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.connection = exports.PostgresConnection.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.database = reader.string();
                    break;
                case 3:
                    message.user = reader.string();
                    break;
                case 4:
                    message.password = common_1.Secret.decode(reader, reader.uint32());
                    break;
                case 5:
                    message.includeTables.push(reader.string());
                    break;
                case 6:
                    message.excludeTables.push(reader.string());
                    break;
                case 8:
                    message.slotByteLagLimit = longToNumber(reader.int64());
                    break;
                case 9:
                    message.serviceSchema = reader.string();
                    break;
                case 13:
                    message.objectTransferSettings = exports.PostgresObjectTransferSettings.decode(reader, reader.uint32());
                    break;
                case 14:
                    message.securityGroups.push(reader.string());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b, _c;
        const message = Object.assign({}, basePostgresSource);
        message.connection =
            object.connection !== undefined && object.connection !== null
                ? exports.PostgresConnection.fromJSON(object.connection)
                : undefined;
        message.database =
            object.database !== undefined && object.database !== null
                ? String(object.database)
                : '';
        message.user = object.user !== undefined && object.user !== null ? String(object.user) : '';
        message.password =
            object.password !== undefined && object.password !== null
                ? common_1.Secret.fromJSON(object.password)
                : undefined;
        message.includeTables = ((_a = object.includeTables) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
        message.excludeTables = ((_b = object.excludeTables) !== null && _b !== void 0 ? _b : []).map((e) => String(e));
        message.slotByteLagLimit =
            object.slotByteLagLimit !== undefined && object.slotByteLagLimit !== null
                ? Number(object.slotByteLagLimit)
                : 0;
        message.serviceSchema =
            object.serviceSchema !== undefined && object.serviceSchema !== null
                ? String(object.serviceSchema)
                : '';
        message.objectTransferSettings =
            object.objectTransferSettings !== undefined && object.objectTransferSettings !== null
                ? exports.PostgresObjectTransferSettings.fromJSON(object.objectTransferSettings)
                : undefined;
        message.securityGroups = ((_c = object.securityGroups) !== null && _c !== void 0 ? _c : []).map((e) => String(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.connection !== undefined &&
            (obj.connection = message.connection
                ? exports.PostgresConnection.toJSON(message.connection)
                : undefined);
        message.database !== undefined && (obj.database = message.database);
        message.user !== undefined && (obj.user = message.user);
        message.password !== undefined &&
            (obj.password = message.password ? common_1.Secret.toJSON(message.password) : undefined);
        if (message.includeTables) {
            obj.includeTables = message.includeTables.map((e) => e);
        }
        else {
            obj.includeTables = [];
        }
        if (message.excludeTables) {
            obj.excludeTables = message.excludeTables.map((e) => e);
        }
        else {
            obj.excludeTables = [];
        }
        message.slotByteLagLimit !== undefined &&
            (obj.slotByteLagLimit = Math.round(message.slotByteLagLimit));
        message.serviceSchema !== undefined && (obj.serviceSchema = message.serviceSchema);
        message.objectTransferSettings !== undefined &&
            (obj.objectTransferSettings = message.objectTransferSettings
                ? exports.PostgresObjectTransferSettings.toJSON(message.objectTransferSettings)
                : undefined);
        if (message.securityGroups) {
            obj.securityGroups = message.securityGroups.map((e) => e);
        }
        else {
            obj.securityGroups = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g;
        const message = Object.assign({}, basePostgresSource);
        message.connection =
            object.connection !== undefined && object.connection !== null
                ? exports.PostgresConnection.fromPartial(object.connection)
                : undefined;
        message.database = (_a = object.database) !== null && _a !== void 0 ? _a : '';
        message.user = (_b = object.user) !== null && _b !== void 0 ? _b : '';
        message.password =
            object.password !== undefined && object.password !== null
                ? common_1.Secret.fromPartial(object.password)
                : undefined;
        message.includeTables = ((_c = object.includeTables) === null || _c === void 0 ? void 0 : _c.map((e) => e)) || [];
        message.excludeTables = ((_d = object.excludeTables) === null || _d === void 0 ? void 0 : _d.map((e) => e)) || [];
        message.slotByteLagLimit = (_e = object.slotByteLagLimit) !== null && _e !== void 0 ? _e : 0;
        message.serviceSchema = (_f = object.serviceSchema) !== null && _f !== void 0 ? _f : '';
        message.objectTransferSettings =
            object.objectTransferSettings !== undefined && object.objectTransferSettings !== null
                ? exports.PostgresObjectTransferSettings.fromPartial(object.objectTransferSettings)
                : undefined;
        message.securityGroups = ((_g = object.securityGroups) === null || _g === void 0 ? void 0 : _g.map((e) => e)) || [];
        return message;
    },
};
const basePostgresTarget = { database: '', user: '', cleanupPolicy: 0, securityGroups: '' };
exports.PostgresTarget = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.connection !== undefined) {
            exports.PostgresConnection.encode(message.connection, writer.uint32(10).fork()).ldelim();
        }
        if (message.database !== '') {
            writer.uint32(18).string(message.database);
        }
        if (message.user !== '') {
            writer.uint32(26).string(message.user);
        }
        if (message.password !== undefined) {
            common_1.Secret.encode(message.password, writer.uint32(34).fork()).ldelim();
        }
        if (message.cleanupPolicy !== 0) {
            writer.uint32(40).int32(message.cleanupPolicy);
        }
        for (const v of message.securityGroups) {
            writer.uint32(58).string(v);
        }
        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({}, basePostgresTarget);
        message.securityGroups = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.connection = exports.PostgresConnection.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.database = reader.string();
                    break;
                case 3:
                    message.user = reader.string();
                    break;
                case 4:
                    message.password = common_1.Secret.decode(reader, reader.uint32());
                    break;
                case 5:
                    message.cleanupPolicy = reader.int32();
                    break;
                case 7:
                    message.securityGroups.push(reader.string());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, basePostgresTarget);
        message.connection =
            object.connection !== undefined && object.connection !== null
                ? exports.PostgresConnection.fromJSON(object.connection)
                : undefined;
        message.database =
            object.database !== undefined && object.database !== null
                ? String(object.database)
                : '';
        message.user = object.user !== undefined && object.user !== null ? String(object.user) : '';
        message.password =
            object.password !== undefined && object.password !== null
                ? common_1.Secret.fromJSON(object.password)
                : undefined;
        message.cleanupPolicy =
            object.cleanupPolicy !== undefined && object.cleanupPolicy !== null
                ? (0, common_1.cleanupPolicyFromJSON)(object.cleanupPolicy)
                : 0;
        message.securityGroups = ((_a = object.securityGroups) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.connection !== undefined &&
            (obj.connection = message.connection
                ? exports.PostgresConnection.toJSON(message.connection)
                : undefined);
        message.database !== undefined && (obj.database = message.database);
        message.user !== undefined && (obj.user = message.user);
        message.password !== undefined &&
            (obj.password = message.password ? common_1.Secret.toJSON(message.password) : undefined);
        message.cleanupPolicy !== undefined &&
            (obj.cleanupPolicy = (0, common_1.cleanupPolicyToJSON)(message.cleanupPolicy));
        if (message.securityGroups) {
            obj.securityGroups = message.securityGroups.map((e) => e);
        }
        else {
            obj.securityGroups = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = Object.assign({}, basePostgresTarget);
        message.connection =
            object.connection !== undefined && object.connection !== null
                ? exports.PostgresConnection.fromPartial(object.connection)
                : undefined;
        message.database = (_a = object.database) !== null && _a !== void 0 ? _a : '';
        message.user = (_b = object.user) !== null && _b !== void 0 ? _b : '';
        message.password =
            object.password !== undefined && object.password !== null
                ? common_1.Secret.fromPartial(object.password)
                : undefined;
        message.cleanupPolicy = (_c = object.cleanupPolicy) !== null && _c !== void 0 ? _c : 0;
        message.securityGroups = ((_d = object.securityGroups) === null || _d === void 0 ? void 0 : _d.map((e) => e)) || [];
        return message;
    },
};
var globalThis = (() => {
    if (typeof globalThis !== 'undefined')
        return globalThis;
    if (typeof self !== 'undefined')
        return self;
    if (typeof window !== 'undefined')
        return window;
    if (typeof global !== 'undefined')
        return global;
    throw 'Unable to locate global object';
})();
function longToNumber(long) {
    if (long.gt(Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
    }
    return long.toNumber();
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
