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


# _junior_school_math_manager
# JuniorSchoolMathManager

        
class JuniorSchoolMathManager(BaseManager):
    '''
    JuniorSchoolMathManager
    Example:
        ke = JuniorSchoolMathManager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printProblemTypes()
        
    Pass param audio_on = True to get audio widget.
        
    '''    
    _OPR_TYPE_COUNT = 10
    
    def __new__(cls, *args, **kwargs):
        instance = super(JuniorSchoolMathManager, cls).__new__(cls, *args, **kwargs)
        for base_class in JuniorSchoolMathManager.__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_2_overview',
            '_problem_grade_3_overview',
            '_problem_grade_4_overview',
            ])
        pass


    def _problem_grade_2_overview(self, *args, **kwargs):
        '''
        :audio_on = False. If True, audio widget will be shown.
        '''
        folder_path = "question_bank/math/grade2"
        search_file_paths = [
                "2"
            ]
        
        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_3_overview(self, *args, **kwargs):
        '''
        :audio_on = False. If True, audio widget will be shown.
        '''
        folder_path = "question_bank/math/grade3"
        search_file_paths = [
                "3", "word_problems"
            ]
        
        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_4_overview(self, *args, **kwargs):
        '''
        :audio_on = False. If True, audio widget will be shown.
        '''
        folder_path = "question_bank/math/grade4/common"
        search_file_paths = ".txt"
        
        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)


