"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackupRetentionPolicyServiceClient = exports.BackupRetentionPolicyServiceService = exports.DeleteBackupRetentionPolicyResponse = exports.DeleteBackupRetentionPolicyRequest = exports.CreateBackupRetentionPolicyResponse = exports.CreateBackupRetentionPolicyRequest = exports.ListBackupRetentionPoliciesResponse = exports.ListBackupRetentionPoliciesRequest = 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 backup_retention_policy_1 = require("../../../../../yandex/cloud/mdb/postgresql/v1/backup_retention_policy");
exports.protobufPackage = 'yandex.cloud.mdb.postgresql.v1';
const baseListBackupRetentionPoliciesRequest = {
    clusterId: '',
    pageSize: 0,
    pageToken: '',
};
exports.ListBackupRetentionPoliciesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        if (message.pageSize !== 0) {
            writer.uint32(16).int64(message.pageSize);
        }
        if (message.pageToken !== '') {
            writer.uint32(26).string(message.pageToken);
        }
        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({}, baseListBackupRetentionPoliciesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                case 2:
                    message.pageSize = longToNumber(reader.int64());
                    break;
                case 3:
                    message.pageToken = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListBackupRetentionPoliciesRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.pageSize =
            object.pageSize !== undefined && object.pageSize !== null ? Number(object.pageSize) : 0;
        message.pageToken =
            object.pageToken !== undefined && object.pageToken !== null
                ? String(object.pageToken)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        message.pageSize !== undefined && (obj.pageSize = Math.round(message.pageSize));
        message.pageToken !== undefined && (obj.pageToken = message.pageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseListBackupRetentionPoliciesRequest);
        message.clusterId = (_a = object.clusterId) !== 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 : '';
        return message;
    },
};
const baseListBackupRetentionPoliciesResponse = { nextPageToken: '' };
exports.ListBackupRetentionPoliciesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.policies) {
            backup_retention_policy_1.BackupRetentionPolicy.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({}, baseListBackupRetentionPoliciesResponse);
        message.policies = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.policies.push(backup_retention_policy_1.BackupRetentionPolicy.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({}, baseListBackupRetentionPoliciesResponse);
        message.policies = ((_a = object.policies) !== null && _a !== void 0 ? _a : []).map((e) => backup_retention_policy_1.BackupRetentionPolicy.fromJSON(e));
        message.nextPageToken =
            object.nextPageToken !== undefined && object.nextPageToken !== null
                ? String(object.nextPageToken)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.policies) {
            obj.policies = message.policies.map((e) => e ? backup_retention_policy_1.BackupRetentionPolicy.toJSON(e) : undefined);
        }
        else {
            obj.policies = [];
        }
        message.nextPageToken !== undefined && (obj.nextPageToken = message.nextPageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseListBackupRetentionPoliciesResponse);
        message.policies = ((_a = object.policies) === null || _a === void 0 ? void 0 : _a.map((e) => backup_retention_policy_1.BackupRetentionPolicy.fromPartial(e))) || [];
        message.nextPageToken = (_b = object.nextPageToken) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseCreateBackupRetentionPolicyRequest = {
    clusterId: '',
    retainForDays: 0,
    description: '',
    policyName: '',
};
exports.CreateBackupRetentionPolicyRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.clusterId !== '') {
            writer.uint32(10).string(message.clusterId);
        }
        if (message.cron !== undefined) {
            backup_retention_policy_1.CronTab.encode(message.cron, writer.uint32(18).fork()).ldelim();
        }
        if (message.retainForDays !== 0) {
            writer.uint32(24).int64(message.retainForDays);
        }
        if (message.description !== '') {
            writer.uint32(34).string(message.description);
        }
        if (message.policyName !== '') {
            writer.uint32(42).string(message.policyName);
        }
        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({}, baseCreateBackupRetentionPolicyRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.clusterId = reader.string();
                    break;
                case 2:
                    message.cron = backup_retention_policy_1.CronTab.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.retainForDays = longToNumber(reader.int64());
                    break;
                case 4:
                    message.description = reader.string();
                    break;
                case 5:
                    message.policyName = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCreateBackupRetentionPolicyRequest);
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.cron =
            object.cron !== undefined && object.cron !== null
                ? backup_retention_policy_1.CronTab.fromJSON(object.cron)
                : undefined;
        message.retainForDays =
            object.retainForDays !== undefined && object.retainForDays !== null
                ? Number(object.retainForDays)
                : 0;
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.policyName =
            object.policyName !== undefined && object.policyName !== null
                ? String(object.policyName)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        message.cron !== undefined &&
            (obj.cron = message.cron ? backup_retention_policy_1.CronTab.toJSON(message.cron) : undefined);
        message.retainForDays !== undefined &&
            (obj.retainForDays = Math.round(message.retainForDays));
        message.description !== undefined && (obj.description = message.description);
        message.policyName !== undefined && (obj.policyName = message.policyName);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = Object.assign({}, baseCreateBackupRetentionPolicyRequest);
        message.clusterId = (_a = object.clusterId) !== null && _a !== void 0 ? _a : '';
        message.cron =
            object.cron !== undefined && object.cron !== null
                ? backup_retention_policy_1.CronTab.fromPartial(object.cron)
                : undefined;
        message.retainForDays = (_b = object.retainForDays) !== null && _b !== void 0 ? _b : 0;
        message.description = (_c = object.description) !== null && _c !== void 0 ? _c : '';
        message.policyName = (_d = object.policyName) !== null && _d !== void 0 ? _d : '';
        return message;
    },
};
const baseCreateBackupRetentionPolicyResponse = {};
exports.CreateBackupRetentionPolicyResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.policy !== undefined) {
            backup_retention_policy_1.BackupRetentionPolicy.encode(message.policy, 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({}, baseCreateBackupRetentionPolicyResponse);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.policy = backup_retention_policy_1.BackupRetentionPolicy.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCreateBackupRetentionPolicyResponse);
        message.policy =
            object.policy !== undefined && object.policy !== null
                ? backup_retention_policy_1.BackupRetentionPolicy.fromJSON(object.policy)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.policy !== undefined &&
            (obj.policy = message.policy
                ? backup_retention_policy_1.BackupRetentionPolicy.toJSON(message.policy)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseCreateBackupRetentionPolicyResponse);
        message.policy =
            object.policy !== undefined && object.policy !== null
                ? backup_retention_policy_1.BackupRetentionPolicy.fromPartial(object.policy)
                : undefined;
        return message;
    },
};
const baseDeleteBackupRetentionPolicyRequest = { policyId: '', clusterId: '' };
exports.DeleteBackupRetentionPolicyRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.policyId !== '') {
            writer.uint32(10).string(message.policyId);
        }
        if (message.clusterId !== '') {
            writer.uint32(18).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({}, baseDeleteBackupRetentionPolicyRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.policyId = reader.string();
                    break;
                case 2:
                    message.clusterId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteBackupRetentionPolicyRequest);
        message.policyId =
            object.policyId !== undefined && object.policyId !== null
                ? String(object.policyId)
                : '';
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.policyId !== undefined && (obj.policyId = message.policyId);
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseDeleteBackupRetentionPolicyRequest);
        message.policyId = (_a = object.policyId) !== null && _a !== void 0 ? _a : '';
        message.clusterId = (_b = object.clusterId) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseDeleteBackupRetentionPolicyResponse = {};
exports.DeleteBackupRetentionPolicyResponse = {
    encode(_, writer = minimal_1.default.Writer.create()) {
        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({}, baseDeleteBackupRetentionPolicyResponse);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(_) {
        const message = Object.assign({}, baseDeleteBackupRetentionPolicyResponse);
        return message;
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    fromPartial(_) {
        const message = Object.assign({}, baseDeleteBackupRetentionPolicyResponse);
        return message;
    },
};
/** A set of methods for managing PostgreSQL Cluster backup retention policies. */
exports.BackupRetentionPolicyServiceService = {
    /** List all retention policies. */
    list: {
        path: '/yandex.cloud.mdb.postgresql.v1.BackupRetentionPolicyService/List',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListBackupRetentionPoliciesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListBackupRetentionPoliciesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListBackupRetentionPoliciesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListBackupRetentionPoliciesResponse.decode(value),
    },
    /** Add a new retention policy. */
    create: {
        path: '/yandex.cloud.mdb.postgresql.v1.BackupRetentionPolicyService/Create',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.CreateBackupRetentionPolicyRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.CreateBackupRetentionPolicyRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.CreateBackupRetentionPolicyResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.CreateBackupRetentionPolicyResponse.decode(value),
    },
    /** Delete retention policy. */
    delete: {
        path: '/yandex.cloud.mdb.postgresql.v1.BackupRetentionPolicyService/Delete',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.DeleteBackupRetentionPolicyRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.DeleteBackupRetentionPolicyRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.DeleteBackupRetentionPolicyResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.DeleteBackupRetentionPolicyResponse.decode(value),
    },
};
exports.BackupRetentionPolicyServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.BackupRetentionPolicyServiceService, 'yandex.cloud.mdb.postgresql.v1.BackupRetentionPolicyService');
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();
}
