from .base_expert import BaseExpert
from .a1_english import EnglishExpert
from .a2_urdu import UrduExpert
from .a3_mathematics import MathematicsExpert
from .a4_science import ScienceExpert
from .a5_islamiat import IslamiatExpert
from .a6_social_studies import SocialStudiesExpert
from .a7_computer_science import ComputerScienceExpert
from .a8_handwriting import HandwritingExpert
from .a9_master_auditor import MasterAuditorExpert
from .understanding.u_orchestrator import UnderstandingExpert


def get_expert_prompt(question, subject, tier=2, path='memorize', medium='EN', pasted_answer=None):
    subject_lower = str(subject).lower().strip()

    if path == 'understand':
        expert = UnderstandingExpert()
    elif "math" in subject_lower or "algebra" in subject_lower or "geometry" in subject_lower:
        expert = MathematicsExpert()
    elif any(s in subject_lower for s in ["physics", "chemistry", "biology", "science"]):
        expert = ScienceExpert()
    elif any(s in subject_lower for s in ["computer", " cs", "it"]):
        expert = ComputerScienceExpert()
    elif any(s in subject_lower for s in ["islamiat", "islamiyat", "tarjumatul quran", "tarjumat"]):
        expert = IslamiatExpert()
    elif "urdu" in subject_lower:
        expert = UrduExpert()
    elif "english" in subject_lower:
        expert = EnglishExpert()
    elif any(s in subject_lower for s in ["social", "history", "geography", "general knowledge", "gk", "civics", "economic", "economics"]):
        expert = SocialStudiesExpert()
    elif "handwriting" in subject_lower:
        expert = HandwritingExpert()
    else:
        expert = BaseExpert()

    # Generate the base prompt for the specific subject
    prompt = expert.get_prompt(question, subject, tier, medium=medium, pasted_answer=pasted_answer)

    # Append the Master Auditor rules to ensure the AI does not skip any steps
    auditor = MasterAuditorExpert()
    audit_rules = auditor.get_json_schema(question.question_text or '', question.model_answer or '')
    prompt = prompt + "\n\nMASTER AUDITOR VERIFICATION:\n" + audit_rules

    return prompt
