'''
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

# _higher_math_manager
# HigherMathManager

        
class HigherMathManager(BaseManager):
    '''
    HigherMathManager
    Example:
        ke = HigherMathManager()
        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(HigherMathManager, cls).__new__(cls, *args, **kwargs)
        for base_class in HigherMathManager.__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_grade_12_aops_question',
            '_problem_math_difficult_problems',
            '_problem_selected_exercises',
            ])
        pass

    def _problem_grade_12_aops_question(self, *args, **kwargs):
        folder_path = "question_bank/math/grade_12_aops"
        search_file_paths = "12"
        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_math_difficult_problems(self, *args, **kwargs):
        folder_path = "question_bank/math/difficult_problems"
        search_file_paths = [
                "math_difficult_problems",
                "math_california_hs_exit",
                "as-a-level-mathematics-9709-paper"
            ]
        
        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_selected_exercises(self, *args, **kwargs):
        folder_path = "question_bank/math/selected_exercises"
        search_file_paths = [
                "exercises"
            ]
        
        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)


