"""Build the AI prompt for teacher-initiated copy/paste workflow. No API calls."""


def build_prompt(kc):
    terms = getattr(kc, 'key_terms', None)
    if isinstance(terms, list):
        terms = ', '.join(str(t) for t in terms)
    elif terms is None:
        terms = ''

    return (
        "You are a pedagogical assistant for Punjab Board students in Pakistan.\n"
        "\n"
        "Task: Generate Roman Urdu scaffolding for the following Knowledge Component (KC).\n"
        "\n"
        "Rules:\n"
        "- 'Roman Urdu' means Latin-script Hindi/Urdu, NOT Urdu script.\n"
        "- Use simple, conversational language appropriate for the grade level.\n"
        "- Keep it culturally appropriate and educationally sound.\n"
        "- The intro should be 2-3 sentences. Hints should get progressively harder.\n"
        "\n"
        "KC details:\n"
        f"- Code: {kc.code}\n"
        f"- Subject: {getattr(kc, 'subject', '') or '(not specified)'}\n"
        f"- Chapter: {getattr(kc, 'chapter', '') or '(not specified)'}\n"
        f"- Title: {getattr(kc, 'title', '') or '(not specified)'}\n"
        f"- Description: {getattr(kc, 'description', '') or '(not specified)'}\n"
        f"- Key terms: {terms or '(not specified)'}\n"
        "\n"
        "Return ONLY valid JSON in this exact format:\n"
        "{\n"
        '  "roman_urdu_intro": "2-3 sentences explaining this concept in Roman Urdu",\n'
        '  "vocabulary_bridge": {"EnglishTerm1": "RomanUrdu1", "EnglishTerm2": "RomanUrdu2"},\n'
        '  "socratic_hints_ur": ["First hint in Roman Urdu", "Second hint in Roman Urdu"]\n'
        "}\n"
        "\n"
        "Do not include any text, markdown fences, or explanation outside the JSON object."
    )
