/**
 * Systemctl fix handler.
 * Runs systemctl commands (enable, start, restart, reload, stop) via programmatic SSH.
 * Supports `--now` flag and combined `enable --now` syntax.
 */
import { sshExec } from "../../../utils/ssh.js";
import { cmd } from "../../../utils/sshCommand.js";
// systemctl <action> [--now] <service>
const SYSTEMCTL_REGEX = /^systemctl\s+(enable|start|restart|reload|stop)\s+(--now\s+)?(\S+)$/;
export const systemctlHandler = {
    match(fixCommand) {
        const m = fixCommand.match(SYSTEMCTL_REGEX);
        if (!m)
            return null;
        return {
            type: "systemctl",
            action: m[1],
            now: !!m[2],
            service: m[3],
        };
    },
    async execute(ip, params) {
        const action = params.action;
        const now = params.now;
        const service = params.service;
        const args = ["systemctl", action];
        if (now)
            args.push("--now");
        args.push(service);
        const result = await sshExec(ip, cmd(...args));
        if (result.code !== 0) {
            return { success: false, error: result.stderr || `systemctl ${action} ${service} failed` };
        }
        return { success: true };
    },
};
//# sourceMappingURL=systemctl.js.map