from pathlib import Path

import click


@click.group()
def cli():
    pass


@cli.command("evaluate")
@click.argument(
    "srs_std_dirs_root", type=click.Path(exists=True, file_okay=False, path_type=Path)
)
@click.argument(
    "srs_orig_dir", type=click.Path(exists=True, file_okay=False, path_type=Path)
)
@click.option(
    "--srs_title",
    "-t",
    type=str,
    default=None,
    help="SRS title for decontextualization.",
)
@click.option(
    "--count",
    "-n",
    type=int,
    default=3,
    help="Number of decontextualizations to perform.",
)
@click.option(
    "--force",
    "-f",
    is_flag=True,
    default=False,
    help="Force to decontextualize regardless of whether the cache exists or not.",
)
def call_main_evaluate(
    srs_std_dirs_root: Path,
    srs_orig_dir: Path,
    srs_title: str,
    count: int,
    force: bool,
):
    srs_title = srs_title or srs_orig_dir.parent.stem

    from srs2std.evaluate.main import main

    main(
        srs_std_dirs_root,
        srs_orig_dir,
        srs_title,
        count,
        force,
    )


@cli.command("generate")
@click.argument(
    "srs_path", type=click.Path(exists=True, dir_okay=False, path_type=Path)
)
@click.option(
    "--std_template_path",
    "-t",
    type=click.Path(exists=True, dir_okay=False, path_type=Path),
    default=Path("iso_template.yaml"),
    help="Path to restructuring template (in the json format).",
)
@click.option(
    "--output_dir",
    "-o",
    type=click.Path(file_okay=False, path_type=Path),
    default=Path("out"),
    help="Path to the output directory.",
)
@click.option(
    "--prompt_pattern",
    "-p",
    type=click.Choice(["naive_all", "naive_each"]),
    default="naive_all",
    help="Prompt pattern to restructure.",
)
@click.option(
    "--llm_name",
    "-ln",
    type=click.Choice(["gemini_2_5_flash", "gemini_2_5_pro", "gpt_4o", "gpt_5"]),
    default="gemini_2_5_flash",
    help="Generative AI model for standardization.",
)
def call_main_generate(
    srs_path: Path,
    std_template_path: Path,
    output_dir: Path,
    prompt_pattern: str,
    llm_name: str,
):
    output_dir = output_dir / srs_path.parent.stem
    output_dir.mkdir(parents=True, exist_ok=True)

    from srs2std.generate.main import main

    main(
        srs_path,
        std_template_path,
        output_dir,
        prompt_pattern,
        llm_name,
    )
