"""
Translation prompt factory for Azure OpenAI Chat Completions.

Expose: make_messages(example: dict, **kwargs) -> List[dict]
Expected example: {"text": "<english text to translate>"}
Optional kwargs:
  - lang_prefix: one of {"msa","ajp","arz","en"}  # target variety
"""
from typing import Dict, List

VARIETY = {
    "en": "English",
    "msa": "Modern Standard Arabic",
    "ajp": "Levantine Arabic",
    "arz": "Egyptian Arabic",
    "arq": "Algerian Arabic",
    "ary": "Moroccan Arabic",
    "mwd": "Sudanese Arabic",
    "acm": "Iraqi/Mesopotamian Arabic",
    "auz": "Uzbeki Arabic",
    "ayl": "Libyan Arabic",
    "ayp": "Palestinian Arabic",
    "bau": "Bauchi Arabic",
    "bqi": "Bakhtiari",
    "shu": "Sudanese/Chadian Arabic",
    "acw": "Hijazi Arabic",
    "acq": "Yemeni Arabic",
    "afb": "Gulf/Khaleeji Arabic",
    "acx": "Omani Arabic",
}


def _target_from_prefix(pfx: str) -> str:
    return VARIETY.get(pfx, "Modern Standard Arabic")


def make_messages(example: Dict, lang_prefix: str = "msa", **kwargs) -> List[Dict]:
    text = (example.get("text") or "").strip()
    source_lang = "English"  # because we translate en_* fields
    target_lang = _target_from_prefix(lang_prefix)

    # system = ( ##  used for EN- ajp
    #     f"You are a professional translator. "
    #     f"Translate from {source_lang} to {target_lang}. "
    #     f"Output only the translation. Do not add notes or explanations."
    # )

    system = f"""
        You are a culturally grounded and dialect-aware professional translator. Your task is to translate English text into {target_lang}, ensuring the translation is idiomatic, natural, and commonly used in that dialect.

        Do NOT translate into Modern Standard Arabic (MSA). Avoid literal or formal expressions. Focus on fluency, regional vocabulary, and authentic spoken usage.

        RULES:
        - Output ONLY the translation in {target_lang}.
        - Do NOT include explanations, notes, transliterations, or source text.
        - Do NOT use Modern Standard Arabic or mixed dialects.
        - Output only the translation. Do not add notes or explanations.
        """

    user = f"Source: {source_lang}\n" f"Target: {target_lang}\n" f"Text:\n" f"{text}"

    return [
        {"role": "system", "content": system},
        {"role": "user", "content": user},
    ]
