/**
 * ConsoleChannel — MessagingChannelPort adapter for local console output.
 *
 * Designed for tests and local development. No external API calls.
 * Constructor requires no arguments (defaultStream = process.stdout).
 *
 * ANSI color codes:
 *   info     → cyan
 *   warn     → yellow
 *   error    → red
 *   critical → bright red + bold
 *
 * @public
 */
import { InvalidTargetError } from "../../ports/messaging.js";
/** ANSI escape codes per alert level. */
const LEVEL_ANSI = {
    info: "\x1b[36m", // cyan
    warn: "\x1b[33m", // yellow
    error: "\x1b[31m", // red
    critical: "\x1b[1m\x1b[31m", // bold + red
};
const ANSI_RESET = "\x1b[0m";
export class ConsoleChannel {
    #stream;
    /**
     * @param config - Optional config. All fields optional — usable as `new ConsoleChannel()`.
     */
    constructor(config = {}) {
        this.#stream = config.stream ?? process.stdout;
    }
    async sendAlert(level, title, body) {
        const ansi = LEVEL_ANSI[level];
        const levelTag = `[${level.toUpperCase()}]`;
        this.#write(`${ansi}${levelTag} ${title}${ANSI_RESET}\n${body}\n`);
    }
    async sendMessage(target, text) {
        if (!target || target.trim() === "") {
            throw new InvalidTargetError("ConsoleChannel.sendMessage requires a non-empty target", target);
        }
        this.#write(`[MSG→${target.trim()}] ${text}\n`);
    }
    #write(line) {
        this.#stream.write(line);
    }
}
//# sourceMappingURL=console.js.map