"""
aquin-inspect — CLI entry point for local inspection server.

Usage
─────
    # Full inspection (model + data), GPU recommended
    aquin-inspect --model llama-3.2-1b --api-key aq-...

    # Data-only (CPU fine)
    aquin-inspect --data-only --api-key aq-...
"""

import argparse
import sys


def main():
    parser = argparse.ArgumentParser(
        prog="aquin-inspect",
        description="Start a local Aquin inspection server and connect it to the dashboard.",
    )
    parser.add_argument("--api-key",  required=True,                       help="Your Aquin API key (aq-...)")
    parser.add_argument("--model",    default="llama-3.2-1b",              help="Model to load (default: llama-3.2-1b)")
    parser.add_argument("--data-only",action="store_true",                  help="Skip model loading — data inspection only")
    parser.add_argument("--port",     type=int, default=7863,               help="Local port (default: 7863)")
    parser.add_argument("--base-url", default="https://api.aquin.app",      help="Aquin API base URL")
    parser.add_argument("--openai-key", default=None,                       help="OpenAI API key for feature labeling (optional)")
    args = parser.parse_args()

    from aquin.inspect import inspect, data_inspect

    if args.data_only:
        session = data_inspect(
            api_key=args.api_key,
            base_url=args.base_url,
            port=args.port,
        )
    else:
        session = inspect(
            model_id=args.model,
            api_key=args.api_key,
            base_url=args.base_url,
            port=args.port,
            openai_api_key=args.openai_key,
        )

    print(f"\n[aquin-inspect] Server running. Press Ctrl+C to stop.\n", flush=True)
    try:
        session._server.wait()
    except KeyboardInterrupt:
        pass
    finally:
        session.stop()
        sys.exit(0)


if __name__ == "__main__":
    main()
