import typer
from pathlib import Path

plot_app = typer.Typer()

@plot_app.command()
def plot(    question: str = typer.Argument(
        ...,
        help="The question to send to the LLM. Should be phrased as a plot request.",
    ),
    output: Path = typer.Argument(..., help="Output file for markdown. An img directory will be created in the same place to hold output png files."),
    models: str = typer.Option(
        None,
        help="Comma-separated list of model names to run (default: pulled from profile). "
        "Use `all` to run all known models.",
    ),
    ignore_cache: bool = typer.Option(
        False, "--ignore-cache", help="Ignore disk cache for model queries."
    ),
    n_iter: int = typer.Option(
        1, "--n-iter", "-n", min=1, help="Maximum of attempts to correct LLM coding errors (must be >= 1)."
    ),
    docker_image: str = typer.Option(
        None,
        "--docker-image",
        help="Override the docker image name (default: use value from profile)",
    ),
) -> None:
    '''Generate a plot from english.

    - Will use LLM to generate code

    - Will use docker to run the code and produce the plot

    - Will attempt to fix the errors if the code fixes.

    - Write out a log of all steps and results and timing to a markdown file,
      and images to a `img` directory.

    '''
    from hep_data_llm.plot import plot
    plot(
        question,
        output,
        models,
        ignore_cache,
        error_info=True,
        n_iter=n_iter,
        docker_image=docker_image,
    )

app = typer.Typer()
app.add_typer(plot_app)

if __name__ == "__main__":
    app()
