import typer

from .create import create_app
from .list import list_app
from .run import run_app
from .view import view_app


app = typer.Typer(
    name="bench-af",
    help="""
    🧪 Bench-AF: Testbed for Alignment Faking Detection

    A comprehensive toolkit for evaluating effectiveness of alignment faking
    detection algorithms on a common set of model organisms and environments.

    Use 'bench-af COMMAND --help' for detailed information about each command.

    📚 Examples:
      bench-af list models                    # List all available models
      bench-af run validate-model config.yml # Validate a model with config
      bench-af create model my-new-model      # Create a new model template
    """,
    rich_markup_mode="rich",
    no_args_is_help=True,
)

app.add_typer(run_app, name="run")
app.add_typer(list_app, name="list")
app.add_typer(create_app, name="create")
app.add_typer(view_app, name="view")


@app.command(name="status")
def cli_status() -> None:
    """
    Check the status of the Bench-AF project. 
    """
    from pathlib import Path
    from rich import get_console
    from bench_af.util import find_bench_af_root, is_bench_af_root

    console = get_console()
    console.print("Checking the status of the Bench-AF project...")
    
    if is_bench_af_root(Path.cwd()):
        console.print("Successfully detected an existing Bench-AF project in the current directory.")
        console.print("To see the available components, run: [bold green]bench-af list all[/bold green]")
        return

    current_root = find_bench_af_root()
    if current_root is not None:
        console.print(f"Detected a project in upstream directory at [bold green]{current_root}[/bold green].")
        return
    
    console.print("⚠️  [yellow]You are not in a Bench-AF project.[/yellow]")
    console.print("Please first clone the [bold green]bench-af-components[/bold green] repository by running:")
    console.print("[bold green]git clone https://github.com/xretr0/bench-af-components.git[/bold green]")
    console.print("Then, run: [bold green]cd bench-af-components/src/bench_af_components[/bold green]")


# Main entry point
def main() -> None:
    """
    🧪 Bench-AF: AI Model Benchmarking and Detection Framework

    Entry point for the command-line interface.
    """
    app()


if __name__ == "__main__":
    main()
