import { ensureConfigDirs } from "../../utils/config.js";
import { getProject, deleteProject } from "../../db/repositories/projects.js";
import { notifyDaemonProjectRemoved } from "../notify-project-sync.js";
import { notifyDaemonReRegister } from "../notify-re-register.js";
/**
 * Handle the `pocketcoder remove <projectId>` CLI command.
 * Deletes the project from SQLite. Does NOT delete project files.
 * If daemon is running, sends project_removed message and triggers re-registration with the gateway.
 */
export async function removeCommand(projectId) {
    try {
        await ensureConfigDirs();
        const project = getProject(projectId);
        if (!project) {
            console.error(`Project not found: ${projectId}`);
            process.exitCode = 1;
            return;
        }
        deleteProject(projectId);
        console.log(`Project removed: ${project.name}`);
        // Notify daemon about the removed project and re-register with gateway (if running)
        await notifyDaemonProjectRemoved(projectId);
        await notifyDaemonReRegister();
    }
    catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        console.error(`Failed to remove project: ${message}`);
        process.exitCode = 1;
    }
}
//# sourceMappingURL=remove.js.map