from .base_expert import BaseExpert


class IslamiatExpert(BaseExpert):
    def __init__(self):
        super().__init__()
        self.expert_id = "A5"
        self.expert_name = "Islamiat (Memorize -> Understand -> Apply)"

    def get_json_schema(self, q, a, **_kwargs):
        q_safe = q.replace('"', "'").replace("\n", " ")
        a_safe = a.replace('"', "'").replace("\n", " ")
        return (
            "ISLAMIAT PEDAGOGY:\n"
            "Follow the Memorize -> Understand -> Apply sequence. Do NOT stop at rote memorization.\n\n"
            "STRICT RULES:\n"
            "1. GATED READ: Node 2 is MCQ with exactly one option 'READY - I have read it'.\n"
            "2. CUED RECALL: Every keyword node must be type 'fill_blank'. Blank out ONE keyword from the answer text.\n"
            "3. HINTS: Every QUESTION must have a real hint. For fill_blank, hint = 'Starts with \\'<first letter>\\', <N> letters'.\n"
            "4. UNDERSTANDING CHECK: Add an MCQ that tests the student's understanding of the underlying principle (not just recall).\n"
            "5. APPLICATION: Add a fill_blank question asking: 'How would you apply this teaching in your daily life today?'.\n"
            "6. FULL RECALL: Ask the student to write the COMPLETE answer from memory before the application step.\n"
            "7. GRADING: Final MCQ with options 'Again (1)', 'Hard (3)', 'Good (4)', 'Easy (5)'.\n"
            "8. Every QUESTION must have TWO outgoing edges: correct -> next, wrong -> itself.\n"
            "9. Output ONLY valid JSON. No markdown fences. No commentary.\n\n"
            "REQUIRED SHAPE:\n"
            '{\n'
            '  "nodes": [\n'
            '    {"id": 1, "type": "START", "label": "Begin", "config": {}},\n'
            '    {"id": 2, "type": "QUESTION", "label": "Read", "config": {"type": "mcq", "text": "READ CAREFULLY:\\n\\nQ: ' + q_safe + '\\n\\nA: ' + a_safe + '", "options": ["READY - I have read it"], "correct_answer": "READY - I have read it", "hint": "Click READY"}},\n'
            '    {"id": 3, "type": "QUESTION", "label": "Keyword 1", "config": {"type": "fill_blank", "text": "Fill the blank:\\n\\n' + a_safe + '", "correct_answer": "THE_KEYWORD", "hint": "Starts with X"}},\n'
            '    ... one fill_blank node per keyword (3-6 nodes) ...\n'
            '    {"id": 40, "type": "QUESTION", "label": "Understanding", "config": {"type": "mcq", "text": "What is the underlying principle of this teaching?", "options": ["Correct principle", "Wrong 1", "Wrong 2"], "correct_answer": "Correct principle", "hint": "Think about the deeper meaning"}},\n'
            '    {"id": 50, "type": "QUESTION", "label": "Full Recall", "config": {"type": "fill_blank", "text": "Write the COMPLETE answer from memory:\\n\\n' + q_safe + '", "correct_answer": "' + a_safe + '", "hint": "Recall the full structure"}},\n'
            '    {"id": 55, "type": "QUESTION", "label": "Application", "config": {"type": "fill_blank", "text": "How would you apply this teaching in your daily life today?", "correct_answer": "Any valid application", "hint": "Think of a real action you can take"}},\n'
            '    {"id": 60, "type": "QUESTION", "label": "Grading", "config": {"type": "mcq", "text": "How hard was this?", "options": ["Again (1)", "Hard (3)", "Good (4)", "Easy (5)"], "correct_answer": "Good (4)", "hint": "Be honest"}},\n'
            '    {"id": 61, "type": "END", "label": "Done", "config": {}}\n'
            '  ],\n'
            '  "edges": [\n'
            '    {"from": 1, "to": 2, "condition": "", "priority": 1},\n'
            '    {"from": 2, "to": 3, "condition": "correct", "priority": 1},\n'
            '    {"from": 2, "to": 2, "condition": "wrong", "priority": 2},\n'
            '    ... sequential edges for each keyword node ...\n'
            '    {"from": <last_keyword_id>, "to": 40, "condition": "correct", "priority": 1},\n'
            '    {"from": <last_keyword_id>, "to": <last_keyword_id>, "condition": "wrong", "priority": 2},\n'
            '    {"from": 40, "to": 50, "condition": "correct", "priority": 1},\n'
            '    {"from": 40, "to": 40, "condition": "wrong", "priority": 2},\n'
            '    {"from": 50, "to": 55, "condition": "correct", "priority": 1},\n'
            '    {"from": 50, "to": 50, "condition": "wrong", "priority": 2},\n'
            '    {"from": 55, "to": 60, "condition": "correct", "priority": 1},\n'
            '    {"from": 55, "to": 55, "condition": "wrong", "priority": 2},\n'
            '    {"from": 60, "to": 61, "condition": "correct", "priority": 1}\n'
            '  ]\n'
            '}\n'
        )
