from .base_expert import BaseExpert


class SocialStudiesExpert(BaseExpert):
    def __init__(self):
        super().__init__()
        self.expert_id = "A6"
        self.expert_name = "Social Studies (Historical Thinking)"

    def get_json_schema(self, q, a, **_kwargs):
        q_safe = q.replace('"', "'").replace("\n", " ")
        a_safe = a.replace('"', "'").replace("\n", " ")
        return (
            "SOCIAL STUDIES PEDAGOGY (Historical Thinking):\n"
            "Use Sourcing, Corroboration, and Contextualization. Students must evaluate evidence.\n\n"
            "STRICT RULES:\n"
            "1. GATED READ: Node 2 is MCQ with exactly one option 'READY - I have read it'.\n"
            "2. SOURCING: Add an MCQ asking 'Who created this information? What is the source?' to build source evaluation.\n"
            "3. CORROBORATION: Add an MCQ asking students to compare two perspectives or pieces of evidence.\n"
            "4. CUED RECALL: Every keyword node must be type 'fill_blank'. Blank out ONE keyword from the answer text.\n"
            "5. HINTS: Every QUESTION must have a real hint.\n"
            "6. FULL RECALL: Ask the student to write the COMPLETE answer from memory.\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": "Sourcing", "config": {"type": "mcq", "text": "Who would most likely have created this information? Why does it matter?", "options": ["Correct answer", "Wrong 1", "Wrong 2"], "correct_answer": "Correct answer", "hint": "Think about the source"}},\n'
            '    {"id": 45, "type": "QUESTION", "label": "Corroboration", "config": {"type": "mcq", "text": "How would another perspective view this event differently?", "options": ["Correct answer", "Wrong 1", "Wrong 2"], "correct_answer": "Correct answer", "hint": "Consider multiple viewpoints"}},\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": 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": 45, "condition": "correct", "priority": 1},\n'
            '    {"from": 40, "to": 40, "condition": "wrong", "priority": 2},\n'
            '    {"from": 45, "to": 50, "condition": "correct", "priority": 1},\n'
            '    {"from": 45, "to": 45, "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'
        )
