#!/usr/bin/env python3
"""Entry point — paper micro-MM on Lighter BTC."""
from __future__ import annotations

import argparse
import asyncio
import logging
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))

from src.bot import MicroMMBot  # noqa: E402
from src.config import load_config  # noqa: E402


def main() -> int:
    ap = argparse.ArgumentParser(description="Lighter micro-MM paper bot")
    ap.add_argument(
        "-c",
        "--config",
        default=str(ROOT / "config.yaml"),
        help="Path to config.yaml",
    )
    ap.add_argument(
        "--duration",
        type=float,
        default=None,
        help="Override run.duration_s (seconds)",
    )
    ap.add_argument("-v", "--verbose", action="store_true")
    args = ap.parse_args()

    logging.basicConfig(
        level=logging.DEBUG if args.verbose else logging.INFO,
        format="%(asctime)s %(levelname)s %(name)s: %(message)s",
    )

    cfg = load_config(args.config)
    if args.duration is not None:
        cfg.run.duration_s = args.duration

    if cfg.mode != "paper" or cfg.is_live:
        print(
            "Refus: ce script est paper-only. "
            "mode doit être 'paper' et LIVE ne doit pas être 1.",
            file=sys.stderr,
        )
        return 2

    bot = MicroMMBot(cfg, ROOT)
    try:
        asyncio.run(bot.run())
    except KeyboardInterrupt:
        bot.stop()
        print("\nInterrupted.", flush=True)
    return 0


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