"""Rebuild a center's phrase library from its stored forecasts.

    python -m cli.build_phrases --center sac

import_drupal runs this automatically after an import.
"""

import typer

from app.phrases import rebuild

from .common import center_by_slug, connect

app = typer.Typer()


@app.command()
def main(center: str = typer.Option(...)):
    with connect() as conn:
        n = rebuild(conn, center_by_slug(conn, center)["id"])
    typer.echo(f"built {n['phrases']} phrases ({n['distinct']} distinct) for {center}")


if __name__ == "__main__":
    app()
