"""Linear Canal CLI — main entry point.

Usage:
    linear-canal setup                          Interactive setup wizard
    linear-canal init --project /path/to/project
    linear-canal db                             Browse current project (interactive TUI)
    linear-canal db --global                    Browse ALL indexed projects
    linear-canal watch
    linear-canal serve
    linear-canal daemon install                 Install always-on background MCP server
    linear-canal daemon start / stop / status
    linear-canal profile set minimal|standard
    linear-canal update
"""

from __future__ import annotations

import click
from rich.console import Console

from linear_canal import __version__

console = Console()


@click.group()
@click.version_option(version=__version__, prog_name="linear-canal")
@click.option(
    "--api-url",
    default="http://localhost:3141",
    envvar="LINEAR_CANAL_API_URL",
    help="API server URL",
)
@click.pass_context
def cli(ctx: click.Context, api_url: str) -> None:
    """Linear Canal — Context Intelligence Layer for AI Coding Agents.

    Gives AI coding agents a senior-engineer-level understanding
    of your codebase before they write a single line of code.
    """
    ctx.ensure_object(dict)
    ctx.obj["api_url"] = api_url
    ctx.obj["console"] = console


# Register commands
from linear_canal.commands.init import init_cmd
from linear_canal.commands.add import add_cmd
from linear_canal.commands.profile import profile_cmd
from linear_canal.commands.update import update_cmd
from linear_canal.commands.serve import serve_cmd
from linear_canal.commands.watch import watch_cmd
from linear_canal.commands.setup import setup_cmd
from linear_canal.commands.db import db_cmd
from linear_canal.commands.branch import branch_cmd
from linear_canal.commands.cleanup import cleanup_cmd
from linear_canal.commands.daemon import daemon_cmd

cli.add_command(init_cmd, "init")
cli.add_command(setup_cmd, "setup")
cli.add_command(add_cmd, "add")
cli.add_command(profile_cmd, "profile")
cli.add_command(update_cmd, "update")
cli.add_command(serve_cmd, "serve")
cli.add_command(watch_cmd, "watch")
cli.add_command(db_cmd, "db")
cli.add_command(branch_cmd, "branch")
cli.add_command(cleanup_cmd, "cleanup")
cli.add_command(daemon_cmd, "daemon")


if __name__ == "__main__":
    cli()
