"""Command line entrypoint for generating Telegram review drafts."""

from __future__ import annotations

import argparse
import sys
from pathlib import Path

PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
    sys.path.insert(0, str(PROJECT_ROOT))

from autoshorts.growth_plan import load_testbatch, validate_testbatch
from autoshorts.retention import score_idea_retention
from autoshorts.script_drafts import write_review_drafts


def main() -> None:
    parser = argparse.ArgumentParser(description="Generate Telegram-ready AutoShortsBot review drafts.")
    parser.add_argument("--batch", default="data/drafts/testbatch_001.json", help="Path to testbatch JSON")
    parser.add_argument(
        "--out",
        default="data/reviews/testbatch_001",
        help="Output directory for Markdown review files",
    )
    args = parser.parse_args()

    batch = load_testbatch(Path(args.batch))
    summary = validate_testbatch(batch)
    retention_scores = {idea["id"]: score_idea_retention(idea) for idea in batch.get("ideas", [])}
    paths = write_review_drafts(batch, Path(args.out))

    print(f"Generated {len(paths)} review drafts in {args.out}")
    print(f"Validation: {summary}")
    print(f"Retention: {retention_scores}")


if __name__ == "__main__":
    main()
