from __future__ import annotations

import argparse
import json
from pathlib import Path

from autoshorts.website_companion import export_companion_candidate


def build_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(
        description="Export an AutoShorts review package into the TrueTraceShorts website companion-page pipeline."
    )
    parser.add_argument("--review-package", required=True, type=Path)
    parser.add_argument("--companion-spec", required=True, type=Path)
    parser.add_argument("--website-root", required=True, type=Path)
    parser.add_argument("--run-generator", action="store_true", help="Invoke the website npm generator after writing the candidate JSON.")
    parser.add_argument("--force", action="store_true", help="Pass --force to the website generator when --run-generator is used.")
    parser.add_argument("--prefer-output", action="store_true", help="Prefer review_package.output over media_cache_path for video extraction.")
    return parser


def main() -> None:
    args = build_parser().parse_args()
    plan = export_companion_candidate(
        review_package_path=args.review_package,
        companion_spec_path=args.companion_spec,
        website_root=args.website_root,
        run_generator=args.run_generator,
        force=args.force,
        prefer_media_cache=not args.prefer_output,
    )
    print(json.dumps({"ok": True, **plan.to_dict()}, indent=2))


if __name__ == "__main__":
    main()
