from __future__ import annotations

import typer

from flow_xhs.cli.spec.runtime_contracts import command_description, command_summary
from flow_xhs.services.doctor import execute_doctor
from flow_xhs.cli.context import CliContext
from flow_xhs.cli.runtime import run_sync_command

app = typer.Typer(help=command_summary(("doctor",)), no_args_is_help=False)

def _run_doctor_command(ctx: typer.Context, *, command_name: str) -> None:
    cli_ctx: CliContext = ctx.obj
    run_sync_command(ctx=cli_ctx, command=command_name, func=execute_doctor)


@app.callback(invoke_without_command=True)
def doctor(ctx: typer.Context):
    if ctx.invoked_subcommand:
        return
    _run_doctor_command(ctx, command_name="doctor")


doctor.__doc__ = command_description(("doctor",))


@app.command("run")
def doctor_run(ctx: typer.Context):
    """兼容旧路径：`flow-xhs doctor run`。"""
    _run_doctor_command(ctx, command_name="doctor")
