"""
Test script: call parser_service.parse() directly with a text transcript.
Bypasses Whisper entirely — useful for testing prompts and parser output.

Usage:
    cd C:\\Dev\\Talk2CV\\backend
    .\\venv\\Scripts\\activate
    python scripts/test_parser_only.py <step> "<transcript>"

    step: 1=profil, 2=formation, 3=expérience, 4=skills

Example:
    python scripts/test_parser_only.py 1 "smi Youssef, ana nkhdm f marketing, 3ndi 5 snin d experience"
"""

import sys
import asyncio
import json
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from app.services.parser_service import parser_service


async def main(step: int, transcript: str) -> None:
    result = await parser_service.parse(transcript=transcript, step=step)
    print(json.dumps(result.fields, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("Usage: python scripts/test_parser_only.py <step> \"<transcript>\"")
        print("  step: 1=profil  2=formation  3=expérience  4=skills")
        sys.exit(1)

    try:
        step = int(sys.argv[1])
    except ValueError:
        print(f"ERROR: step must be an integer (1-4), got: {sys.argv[1]!r}")
        sys.exit(1)

    transcript = sys.argv[2]

    try:
        asyncio.run(main(step=step, transcript=transcript))
    except ValueError as e:
        print(f"ERROR: {e}")
        sys.exit(1)
    except Exception as e:
        print(f"ERROR: Unexpected error during parsing: {e}")
        sys.exit(1)
