'''
Created on 02-Aug-2023
@author: bthakur


'''
import random
import inspect
import traceback

from ..helper import BaseHelper

from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate


# _high_school_math_manager
# HighSchoolMathManager

        
class HighSchoolMathManager(BaseManager):
    '''
    HighSchoolMathManager
    Example:
        ke = HighSchoolMathManager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printProblemTypes()
        
    '''    
    _OPR_TYPE_COUNT = 10
    
    def __new__(cls, *args, **kwargs):
        instance = super(HighSchoolMathManager, cls).__new__(cls, *args, **kwargs)
        for base_class in HighSchoolMathManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass
    

    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_junior_difficult_problems',
            '_problem_algebra_2_random_question',
            '_problem_grade_10_aops_question',
            '_problem_grade_sat_question',
            '_problem_grade_9_aops_question',
            '_problem_grade_8_aops_question',
            '_problem_grade_7_question',
            '_problem_grade_6_question',
            ])
        pass

    def _problem_junior_difficult_problems(self, *args, **kwargs):
        folder_path = "question_bank/math/junior_difficult_problems"
        search_file_paths = [
                "brainteasers"
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)


    def _problem_algebra_2_random_question(self, *args, **kwargs):
        folder_path = "question_bank/math/level_2_math/algebra"
        search_file_paths = [
                "algebra"
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)


    def _problem_grade_10_aops_question(self, *args, **kwargs):
        folder_path = "question_bank/math/grade10_aops"
        search_file_paths = [
                "10"
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)

    def _problem_grade_sat_question(self, *args, **kwargs):
        folder_path = "question_bank/math/sat"
        search_file_paths = [
                "sat"
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)

    def _problem_grade_9_aops_question(self, *args, **kwargs):
        folder_path = "question_bank/math/grade9_aops"
        search_file_paths = [
                "USAJMO", "USAMO",
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)


    def _problem_grade_8_aops_question(self, *args, **kwargs):
        folder_path = "question_bank/math/grade8_aops"
        search_file_paths = [
                "8", "AJHSME",
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)


    def _problem_grade_7_question(self, *args, **kwargs):
        folder_path = "question_bank/math/grade7"
        search_file_paths = [
                "7"
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)


    def _problem_grade_6_question(self, *args, **kwargs):
        folder_path = "question_bank/math/grade6"
        search_file_paths = [
                "6"
            ]
        
        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        self._log(f"""
        file_paths = {file_paths}
        """)
        
        file_path = random.choice(file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)
