/**
 * `spectral unbind` — remove the local Studio project binding.
 *
 * Reads `.aexol/aexol.jsonc`, reports what project was unbound, and deletes
 * the file. Idempotent: missing binding is not an error.
 */
import pc from "picocolors";
import { deleteStudioBinding, readStudioBinding, } from "../studio-binding.js";
export async function runUnbind() {
    // ---- Read existing -------------------------------------------------------
    let existing;
    try {
        existing = await readStudioBinding();
    }
    catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        process.stderr.write(pc.red(`Failed to read binding: ${msg}\n`));
        process.exit(1);
    }
    if (!existing) {
        process.stdout.write(pc.dim("No Studio binding found in this directory.\n"));
        return;
    }
    const displayName = existing.name ?? existing.projectId;
    process.stderr.write(`Unbinding from project: ${existing.name ?? "(unnamed)"} (${existing.projectId})\n`);
    // ---- Delete --------------------------------------------------------------
    try {
        await deleteStudioBinding();
    }
    catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        process.stderr.write(pc.red(`Failed to remove binding: ${msg}\n`));
        process.exit(1);
    }
    process.stdout.write(pc.green(`✓ Unbound.\n`));
}
