"""asa deploy — Architecture-safe deployment (Vercel + Supabase)."""

import typer

from ..core import logging as log
from ..core.errors import AsaError
from ..core.paths import find_project_root


def run_deploy(*, check: bool, staging: bool, prod: bool, verbose: bool) -> None:
    """Deploy to Vercel + Supabase."""
    from ..engine_loader import require_engine
    require_engine()
    from ..engine.deployer.deployer import deploy_check, deploy_prod, deploy_staging
    try:
        project_root = find_project_root()

        if check:
            exit_code = deploy_check(project_root)
        elif staging:
            exit_code = deploy_staging(project_root)
        elif prod:
            exit_code = deploy_prod(project_root)
        else:
            log.info("Usage: asa deploy --check | --staging | --prod")
            exit_code = 1

        raise typer.Exit(exit_code)

    except AsaError as e:
        log.error(str(e))
        raise typer.Exit(1)
    except typer.Exit:
        raise
    except Exception as e:
        log.error(f"[INTERNAL ERROR] {e}")
        raise typer.Exit(2)
