"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMaintenanceConfig = getMaintenanceConfig;
exports.updateMaintenanceConfig = updateMaintenanceConfig;
const maintenance_1 = require("../services/maintenance");
/**
 * Return the current maintenance cron configuration and active state.
 *
 * @returns `{ status: 200, data: { config, active } }`
 */
function getMaintenanceConfig() {
    return {
        status: 200,
        data: { config: maintenance_1.maintenanceRegistry.config, active: maintenance_1.maintenanceRegistry.hasConfig },
    };
}
/**
 * Replace the maintenance configuration and restart the cron.
 *
 * Disconnects the current maintenance schedule, registers the new
 * config, and reconnects. The cron begins executing immediately.
 *
 * @param input.schedule — cron expression (e.g. `"0 3 * * *"`)
 * @param input.rules — maintenance rule definitions
 * @returns `{ status: 200, data: { config, restarted: true } }`
 */
async function updateMaintenanceConfig(input) {
    try {
        if (!input.schedule || !Array.isArray(input.rules)) {
            return { status: 400, error: 'schedule (string) and rules (array) are required' };
        }
        await maintenance_1.maintenanceRegistry.disconnect();
        maintenance_1.maintenanceRegistry.register({ schedule: input.schedule, rules: input.rules });
        await maintenance_1.maintenanceRegistry.connect();
        return {
            status: 200,
            data: { config: maintenance_1.maintenanceRegistry.config, restarted: true },
        };
    }
    catch (err) {
        return { status: 500, error: err.message };
    }
}
