#!/usr/bin/env python3
"""Create and seed the Smilegate customer QA benchmark history tables."""

from __future__ import annotations

import argparse
from pathlib import Path
import sys


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

from src.poc4.qa_history_store import QaHistoryStore, ensure_schema


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        "--benchmark",
        type=Path,
        default=ROOT / "config" / "smilegate_qa_benchmark.json",
        help="Customer Excel benchmark JSON generated from the approved QA report.",
    )
    parser.add_argument(
        "--env-file",
        type=Path,
        default=None,
        help="Optional environment file containing the QA DB connection settings.",
    )
    args = parser.parse_args()
    if not args.benchmark.is_file():
        raise SystemExit(f"Benchmark file not found: {args.benchmark}")
    store = QaHistoryStore(env_file=args.env_file)
    ensure_schema(store)
    question_count, historical_insert_count = store.seed_benchmark(args.benchmark)
    print(
        "qa_history_sync"
        f" questions={question_count}"
        f" historical_answers_inserted={historical_insert_count}"
    )
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
