#!/usr/bin/env python3
"""Backfill transcript data from {bid}_sarvamresponse into RAG tables."""
import argparse
import json

from config import Config
from rag_handler import RAGHandler


def main():
    parser = argparse.ArgumentParser(description='Backfill transcripts into MCube AI RAG')
    parser.add_argument('--bid', required=True, help='Business ID')
    parser.add_argument('--limit', type=int, default=2000, help='Max calls to process')
    parser.add_argument('--presales-only', action='store_true', help='Only ingest presales-like calls')
    parser.add_argument('--overwrite-existing', action='store_true', help='Recreate docs/chunks already ingested')
    args = parser.parse_args()

    rag = RAGHandler(Config.__dict__)
    result = rag.backfill_transcripts(
        bid=args.bid,
        presales_only=args.presales_only,
        limit=args.limit,
        overwrite_existing=args.overwrite_existing,
    )
    print(json.dumps(result, indent=2))


if __name__ == '__main__':
    main()
