"""Command-line interface for cv_fruit_ninja."""

from __future__ import annotations

import argparse
from typing import Sequence

from .core import summarize_dataframe


def build_parser() -> argparse.ArgumentParser:
    """Create the command-line parser."""
    parser = argparse.ArgumentParser(
        prog="cv-fruit-ninja",
        description="Run a quick data summary demo from cv_fruit_ninja.",
    )
    parser.add_argument(
        "--sales",
        nargs="*",
        type=float,
        default=[1200.0, 1350.0, 1280.0],
        help="Sales values for the summary demo.",
    )
    parser.add_argument(
        "--cost",
        nargs="*",
        type=float,
        default=[420.0, 460.0, 440.0],
        help="Cost values for the summary demo.",
    )
    return parser


def main(argv: Sequence[str] | None = None) -> int:
    """Execute the CLI and print a numeric summary table."""
    parser = build_parser()
    args = parser.parse_args(argv)

    if len(args.sales) != len(args.cost):
        parser.error("--sales and --cost must have the same number of values")

    summary = summarize_dataframe({"sales": args.sales, "cost": args.cost})
    print(summary.to_string())
    return 0


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