#!/usr/bin/env python3
"""Shim: translate_srt_with_gemini

Delegates to `whisper_project.infra.gemini_adapter.GeminiTranslator.translate_srt`
or falls back to `examples/translate_srt_with_gemini.py`.
"""
from __future__ import annotations

import argparse
import subprocess
import sys


def main():
    p = argparse.ArgumentParser(prog="translate_srt_with_gemini")
    p.add_argument("--in", dest="in_srt", required=True)
    p.add_argument("--out", dest="out_srt", required=True)
    p.add_argument("--gemini-api-key", dest="gemini_api_key", required=False, default=None)
    args = p.parse_args()

    try:
        from whisper_project.infra.gemini_adapter import GeminiTranslator

        g = GeminiTranslator(api_key=args.gemini_api_key)
        g.translate_srt(args.in_srt, args.out_srt)
        return
    except Exception:
        try:
            script = "examples/translate_srt_with_gemini.py"
            cmd = [sys.executable, script, "--in", args.in_srt, "--out", args.out_srt]
            if args.gemini_api_key:
                cmd += ["--gemini-api-key", args.gemini_api_key]
            subprocess.run(cmd, check=True)
            return
        except Exception:
            import logging
            logger = logging.getLogger(__name__)
            logger.exception("Error al ejecutar traducción con Gemini")
            sys.exit(1)


if __name__ == "__main__":
    sys.exit(main() or 0)

