"""ansel CLI — demand forecasting CLI for AIs."""

from __future__ import annotations

import sys

from .commands import files as files_cmd
from .commands import forecast as forecast_cmd
from .commands import models as models_cmd
from .commands import series as series_cmd

COMMANDS = {
    'files': files_cmd.run,
    'series': series_cmd.run,
    'models': models_cmd.run,
    'forecast': forecast_cmd.run,
}


def main() -> None:
    args = sys.argv[1:]

    if not args or args[0] in ('-h', '--help', 'help'):
        print('ansel: demand forecasting CLI for AIs')
        print()
        print('Commands:')
        print('  forecast            Forecast demand from CSV data')
        print('  files               Classify data files')
        print('  series              Detect forecastable series')
        print('  models              Build forecast models')
        print()
        print('Options:')
        print('  --data PATH         CSV file or directory (default: .)')
        print('  --horizon N         Forecast periods (default: 12)')
        print('  --interval STR      week | month | quarter (default: month)')
        sys.exit(0)

    if args[0] in ('-v', '--version'):
        print('ansel 0.2.7')
        sys.exit(0)

    command = args[0]
    handler = COMMANDS.get(command)

    if handler is None:
        print(f"error: unknown command '{command}'", file=sys.stderr)
        print("Run 'ansel --help' for usage.", file=sys.stderr)
        sys.exit(1)

    sys.exit(handler(args[1:]))
