/**
 * Status Command
 *
 * Shows the current daemon health status with optional JSON output.
 */
import { Command, Options } from "@effect/cli";
import { GhostflowClient, isDaemonError, isDaemonNotRunning } from "@ghostflow/client";
import { Console, Effect, pipe } from "effect";
import { msg } from "../constants/ansi.js";
import { formatStatus, formatStatusCompact } from "../formatters/status.js";
// ============================================================================
// Options
// ============================================================================
const jsonOption = Options.boolean("json").pipe(Options.withAlias("j"), Options.withDescription("Output status as JSON"), Options.withDefault(false));
const compactOption = Options.boolean("compact").pipe(Options.withAlias("c"), Options.withDescription("Output status in compact one-liner format"), Options.withDefault(false));
// ============================================================================
// Command Implementation
// ============================================================================
const statusHandler = ({ compact, json }) => pipe(Effect.gen(function* () {
    const client = yield* GhostflowClient;
    const status = yield* client.status();
    if (json) {
        yield* Console.log(JSON.stringify(status, null, 2));
    }
    else if (compact) {
        yield* Console.log(formatStatusCompact(status));
    }
    else {
        yield* Console.log(formatStatus(status));
    }
}), Effect.catchAll((error) => Effect.gen(function* () {
    // Use type guards for proper error handling
    if (isDaemonError(error) && isDaemonNotRunning(error)) {
        // Clean user-friendly message without stack trace
        yield* Console.error(msg.stopped("Ghostflow daemon is not running"));
        yield* Console.error("");
        yield* Console.error("Start the daemon with: ghostflow start");
        // Exit without re-throwing to avoid noisy error logging
        return yield* Effect.void;
    }
    // For other errors, re-throw to get proper error handling
    return yield* Effect.fail(error);
})));
// ============================================================================
// Command Definition
// ============================================================================
export const statusCommand = Command.make("status", { json: jsonOption, compact: compactOption }).pipe(Command.withHandler(statusHandler), Command.withDescription("Show daemon health status"));
//# sourceMappingURL=status.js.map