"""Shared CLI constants and output helpers."""

from __future__ import annotations

import sys
from collections.abc import Mapping

from icsd.core.serialise import canonical_json_dumps

EXIT_OK = 0
EXIT_FINDINGS = 1
EXIT_TOOL_ERROR = 2
CLI_PROG_NAME = "icsd-dpa"
OUTPUT_FORMATS = ("json", "text")


def emit_stderr(message: str) -> None:
    """Write a human-readable CLI message to stderr."""
    print(message, file=sys.stderr)


def emit_stdout(message: str) -> None:
    """Write a human-readable CLI message to stdout."""
    print(message, file=sys.stdout)


def emit_json(payload: Mapping[str, object]) -> None:
    """Write a canonical JSON payload to stdout."""
    print(canonical_json_dumps(payload), file=sys.stdout)
