"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackupRetentionPolicy = exports.CronTab = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const timestamp_1 = require("../../../../../google/protobuf/timestamp");
exports.protobufPackage = 'yandex.cloud.mdb.postgresql.v1';
const baseCronTab = { dayOfMonth: '', month: '', dayOfWeek: '' };
exports.CronTab = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.dayOfMonth !== '') {
            writer.uint32(26).string(message.dayOfMonth);
        }
        if (message.month !== '') {
            writer.uint32(34).string(message.month);
        }
        if (message.dayOfWeek !== '') {
            writer.uint32(42).string(message.dayOfWeek);
        }
        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({}, baseCronTab);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 3:
                    message.dayOfMonth = reader.string();
                    break;
                case 4:
                    message.month = reader.string();
                    break;
                case 5:
                    message.dayOfWeek = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCronTab);
        message.dayOfMonth =
            object.dayOfMonth !== undefined && object.dayOfMonth !== null
                ? String(object.dayOfMonth)
                : '';
        message.month =
            object.month !== undefined && object.month !== null ? String(object.month) : '';
        message.dayOfWeek =
            object.dayOfWeek !== undefined && object.dayOfWeek !== null
                ? String(object.dayOfWeek)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.dayOfMonth !== undefined && (obj.dayOfMonth = message.dayOfMonth);
        message.month !== undefined && (obj.month = message.month);
        message.dayOfWeek !== undefined && (obj.dayOfWeek = message.dayOfWeek);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseCronTab);
        message.dayOfMonth = (_a = object.dayOfMonth) !== null && _a !== void 0 ? _a : '';
        message.month = (_b = object.month) !== null && _b !== void 0 ? _b : '';
        message.dayOfWeek = (_c = object.dayOfWeek) !== null && _c !== void 0 ? _c : '';
        return message;
    },
};
const baseBackupRetentionPolicy = {
    policyId: '',
    clusterId: '',
    policyName: '',
    retainForDays: 0,
    description: '',
};
exports.BackupRetentionPolicy = {
    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);
        }
        if (message.policyName !== '') {
            writer.uint32(26).string(message.policyName);
        }
        if (message.createdAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(34).fork()).ldelim();
        }
        if (message.cron !== undefined) {
            exports.CronTab.encode(message.cron, writer.uint32(42).fork()).ldelim();
        }
        if (message.retainForDays !== 0) {
            writer.uint32(48).int64(message.retainForDays);
        }
        if (message.description !== '') {
            writer.uint32(58).string(message.description);
        }
        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({}, baseBackupRetentionPolicy);
        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;
                case 3:
                    message.policyName = reader.string();
                    break;
                case 4:
                    message.createdAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 5:
                    message.cron = exports.CronTab.decode(reader, reader.uint32());
                    break;
                case 6:
                    message.retainForDays = longToNumber(reader.int64());
                    break;
                case 7:
                    message.description = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseBackupRetentionPolicy);
        message.policyId =
            object.policyId !== undefined && object.policyId !== null
                ? String(object.policyId)
                : '';
        message.clusterId =
            object.clusterId !== undefined && object.clusterId !== null
                ? String(object.clusterId)
                : '';
        message.policyName =
            object.policyName !== undefined && object.policyName !== null
                ? String(object.policyName)
                : '';
        message.createdAt =
            object.createdAt !== undefined && object.createdAt !== null
                ? fromJsonTimestamp(object.createdAt)
                : undefined;
        message.cron =
            object.cron !== undefined && object.cron !== null
                ? exports.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)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.policyId !== undefined && (obj.policyId = message.policyId);
        message.clusterId !== undefined && (obj.clusterId = message.clusterId);
        message.policyName !== undefined && (obj.policyName = message.policyName);
        message.createdAt !== undefined && (obj.createdAt = message.createdAt.toISOString());
        message.cron !== undefined &&
            (obj.cron = message.cron ? exports.CronTab.toJSON(message.cron) : undefined);
        message.retainForDays !== undefined &&
            (obj.retainForDays = Math.round(message.retainForDays));
        message.description !== undefined && (obj.description = message.description);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f;
        const message = Object.assign({}, baseBackupRetentionPolicy);
        message.policyId = (_a = object.policyId) !== null && _a !== void 0 ? _a : '';
        message.clusterId = (_b = object.clusterId) !== null && _b !== void 0 ? _b : '';
        message.policyName = (_c = object.policyName) !== null && _c !== void 0 ? _c : '';
        message.createdAt = (_d = object.createdAt) !== null && _d !== void 0 ? _d : undefined;
        message.cron =
            object.cron !== undefined && object.cron !== null
                ? exports.CronTab.fromPartial(object.cron)
                : undefined;
        message.retainForDays = (_e = object.retainForDays) !== null && _e !== void 0 ? _e : 0;
        message.description = (_f = object.description) !== null && _f !== void 0 ? _f : '';
        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 toTimestamp(date) {
    const seconds = date.getTime() / 1000;
    const nanos = (date.getTime() % 1000) * 1000000;
    return { seconds, nanos };
}
function fromTimestamp(t) {
    let millis = t.seconds * 1000;
    millis += t.nanos / 1000000;
    return new Date(millis);
}
function fromJsonTimestamp(o) {
    if (o instanceof Date) {
        return o;
    }
    else if (typeof o === 'string') {
        return new Date(o);
    }
    else {
        return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
    }
}
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();
}
