from .base_expert import BaseExpert


class MathematicsExpert(BaseExpert):
    def __init__(self):
        super().__init__()
        self.expert_id = "A3"
        self.expert_name = "Mathematics (Stepwise Socratic)"

    def get_json_schema(self, q, a, **_kwargs):
        q_safe = q.replace('"', "'").replace("\n", " ")
        a_safe = a.replace('"', "'").replace("\n", " ")
        return (
            "MATHEMATICS PEDAGOGY (Sequential Scaffolding):\n"
            "Break the problem into 10 to 15 sub-steps. Never skip to the final answer.\n\n"
            "STRICT RULES:\n"
            "1. LOOP FOR EACH STEP: Ask 'What' -> Ask 'How' -> Ask 'Execute' (calculation).\n"
            "2. SCAFFOLD LOCK-IN: Every node's text MUST contain all previously solved steps at the top, so the student sees their progress.\n"
            "3. GATED READ: Node 2 is MCQ with exactly one option 'READY - I have read it'.\n"
            "4. HINTS: Every QUESTION must have a real hint.\n"
            "5. FINAL RECALL: Ask the student to write the complete step-by-step solution (a, b, c, d...).\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 (Build 10-15 nodes using this pattern):\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": "Step 1 - What", "config": {"type": "fill_blank", "text": "Q: ' + q_safe + '\\n\\nStep 1: What will we solve first?", "correct_answer": "[method] hint: [Xleft]"}},\n'
            '    {"id": 4, "type": "QUESTION", "label": "Step 1 - How", "config": {"type": "fill_blank", "text": "Step 1 (What): [student answer]\\n\\nHow will we solve this?", "correct_answer": "[method] hint: [Xleft]"}},\n'
            '    {"id": 5, "type": "QUESTION", "label": "Step 1 - Execute", "config": {"type": "fill_blank", "text": "Step 1 (What): [student answer]\\nStep 1 (How): [student answer]\\n\\nExecute this step", "correct_answer": "[result] hint: [Xleft]"}},\n'
            '    ... repeat What/How/Execute for 10-15 steps ...\n'
            '    {"id": 50, "type": "QUESTION", "label": "Full Recall", "config": {"type": "fill_blank", "text": "Write the complete step-by-step solution for:\\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 all 10-15 steps ...\n'
            '    {"from": <last_step_id>, "to": 50, "condition": "correct", "priority": 1},\n'
            '    {"from": <last_step_id>, "to": <last_step_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'
            '\n'
            '# Y_O_U_R_M_A_T_H_G_U_I_D_E_L_I_N_E_S\n'
            '# [Placeholder for the second expert guidelines to be added here later]\n'
        )
