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


# _advanced_physics_manager
# AdvancedPhysicsManager

# _advanced_physics_manager
# AdvancedPhysicsManager

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


    def _problem_cambridge_physics(self, *args, **kwargs):
        file_paths = self.get_q_bank_factory().search_question_bank_files("question_bank/physics", 
                                                                    "cambridge_problems_in_physics")
        file_path = random.choice(file_paths)
        solution_file_path = self.get_q_bank_factory().get_solution_file_path(file_path)
        if solution_file_path:
            kwargs['solution_file_path'] = solution_file_path
            
        answer_file_path = self.get_q_bank_factory().get_answer_file_path(file_path)
        if answer_file_path:
            kwargs['answer_file_path'] = answer_file_path
            
        
        sOut = f"""
        file_path = {file_path}
        solution_file_path = {solution_file_path}
        answer_file_path = {answer_file_path}
        """
        self._log(sOut)
        #print(sOut)
        
        
        kwargs['has_question_numbers'] = True
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_path, *args, **kwargs)

 