import { CONTROL_PLANE_HOST, CONTROL_PLANE_PORT } from "@pocketcoder/shared";
import { isDaemonRunning } from "./commands/start.js";
/**
 * Notify the running daemon to re-send daemon_register to the gateway.
 * Called after project add/remove to sync the updated project list.
 * Silently skips if daemon is not running or not connected to gateway.
 */
export async function notifyDaemonReRegister() {
    const running = await isDaemonRunning();
    if (!running) {
        return;
    }
    try {
        const url = `http://${CONTROL_PLANE_HOST}:${CONTROL_PLANE_PORT}/re-register`;
        const response = await fetch(url, {
            method: "POST",
            signal: AbortSignal.timeout(15000),
        });
        if (!response.ok) {
            return;
        }
        const body = (await response.json());
        if (body.sent && body.response?.warning === "PROJECT_LIMIT_EXCEEDED") {
            console.warn(`Warning: ${body.response.message ?? `${body.response.ignored} project(s) ignored due to plan limit`}`);
            if (body.response.ignoredProjects && body.response.ignoredProjects.length > 0) {
                console.warn(`Ignored projects: ${body.response.ignoredProjects.join(", ")}`);
            }
        }
    }
    catch {
        // Silently ignore - daemon may not be running or endpoint may not be available
    }
}
//# sourceMappingURL=notify-re-register.js.map