"""linear-canal add — Index a project and register it with Linear Canal.

Alias for `linear-canal setup --project <path>`.
"""
from __future__ import annotations

from pathlib import Path

import click
from rich.console import Console

console = Console()


@click.command("add")
@click.argument("project_path", type=click.Path(exists=True, file_okay=False))
@click.option(
    "--profile",
    type=click.Choice(["minimal", "standard"]),
    default=None,
    help="Embedding profile (default: auto-detected from RAM).",
)
@click.option(
    "--force",
    is_flag=True,
    default=False,
    help="Re-index even if already initialised.",
)
def add_cmd(project_path: str, profile: str | None, force: bool) -> None:
    """Index a project and register it with Linear Canal.

    Equivalent to:  linear-canal setup --project <path>

    Example:
        linear-canal add ~/projects/my-app
        linear-canal add ~/projects/my-app --profile minimal
    """
    from linear_canal.pipeline import run_pipeline

    resolved = Path(project_path).resolve()
    console.print(f"[bold]Indexing[/bold] [cyan]{resolved}[/cyan] ...\n")

    run_pipeline(
        target_dir=resolved,
        project_id=resolved.name,
        profile=profile,
        verbose=True,
    )
    console.print(
        f"\n[bold green]✓ Done.[/bold green] "
        f"[dim]Run [bold]linear-canal db --global[/bold] to inspect the index.[/dim]"
    )
