from .base_expert import BaseExpert


class EnglishExpert(BaseExpert):
    def __init__(self):
        super().__init__()
        self.expert_id = "A1"
        self.expert_name = "English (QAR + Retelling)"

    def get_json_schema(self, q, a, **_kwargs):
        q_safe = q.replace('"', "'").replace("\n", " ")
        a_safe = a.replace('"', "'").replace("\n", " ")
        return (
            "ENGLISH PEDAGOGY (QAR + Retelling):\n"
            "Use Question-Answer Relationship (Right There, Think and Search, Author and Me) to build inference skills.\n\n"
            "STRICT RULES:\n"
            "1. GATED READ: Node 2 is MCQ with exactly one option 'READY - I have read it'.\n"
            "2. VOCAB PREVIEW: Before the main text, present 1-2 key vocabulary words in a micro-context (simple sentence).\n"
            "3. QAR RECALL: Every keyword node must be type 'fill_blank'. Blank out ONE keyword from the answer text.\n"
            "4. HINTS: Every QUESTION must have a real hint. For fill_blank, hint = 'Starts with \\'<first letter>\\', <N> letters'.\n"
            "5. RETELLING: The final recall asks the student to reconstruct the entire text from memory (Retelling).\n"
            "6. GRADING: Final MCQ with options 'Again (1)', 'Hard (3)', 'Good (4)', 'Easy (5)'.\n"
            "7. Every QUESTION must have TWO outgoing edges: correct -> next, wrong -> itself.\n"
            "8. 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": 50, "type": "QUESTION", "label": "Full Recall", "config": {"type": "fill_blank", "text": "Retell the COMPLETE answer from memory:\\n\\n' + q_safe + '", "correct_answer": "' + a_safe + '", "hint": "Recall the full structure"}},\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": 50, "condition": "correct", "priority": 1},\n'
            '    {"from": <last_keyword_id>, "to": <last_keyword_id>, "condition": "wrong", "priority": 2},\n'
            '    {"from": 50, "to": 60, "condition": "correct", "priority": 1},\n'
            '    {"from": 50, "to": 50, "condition": "wrong", "priority": 2},\n'
            '    {"from": 60, "to": 61, "condition": "correct", "priority": 1}\n'
            '  ]\n'
            '}\n'
        )
