"""CLI entry point and compatibility surface for ICSD."""

from __future__ import annotations

from collections.abc import Sequence

from ._demo import DEFAULT_DEMO_OUTPUT, run_demo
from ._lint import LINT_BASELINE_PROFILE, LINT_POLICY_PROFILE, run_lint
from ._parser import build_parser
from ._shared import CLI_PROG_NAME, EXIT_FINDINGS, EXIT_OK, EXIT_TOOL_ERROR
from ._verify import run_verify

__all__ = (
    "CLI_PROG_NAME",
    "DEFAULT_DEMO_OUTPUT",
    "EXIT_FINDINGS",
    "EXIT_OK",
    "EXIT_TOOL_ERROR",
    "LINT_BASELINE_PROFILE",
    "LINT_POLICY_PROFILE",
    "build_parser",
    "main",
)


def main(argv: Sequence[str] | None = None) -> int:
    """Run the ICSD CLI."""
    parser = build_parser()
    args = parser.parse_args(argv)
    if args.command == "demo":
        return run_demo(args.output)
    if args.command == "verify":
        return run_verify(args.evidence_json, output_format=args.output_format)
    if args.command == "lint":
        return run_lint(
            args.path,
            profile=args.profile,
            output_format=args.output_format,
            jobs=args.jobs,
        )
    parser.print_help()
    return EXIT_TOOL_ERROR


if __name__ == "__main__":
    raise SystemExit(main())
