'''
Created on 4-Jan-2023

@author: b thakur

'''

import random
import inspect
import traceback

from ..helper import BaseHelper

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

from sympy import UnevaluatedExpr as ueval
from sympy import latex



# _interesting_physics_manager
# InterestingPhysicsManager

class InterestingPhysicsManager(BaseManager):
    '''
    InterestingPhysicsManager
    Example:
        ke = InterestingPhysicsManager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printProblemTypes()
        
    '''    
    
    def __new__(cls, *args, **kwargs):
        instance = super(InterestingPhysicsManager, cls).__new__(cls, *args, **kwargs)
        for base_class in InterestingPhysicsManager.__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_unbreakable_glass',
            '_problem_night_vision_goggles',
            '_problem_the_men_who_promised_the_impossible_unlimited_energy',

            
            ])
        pass



    def _problem_unbreakable_glass(self, *args, **kwargs):
        folder_path = "comprehension/physics/interesting_physics"
        search = "unbreakable_glass.txt"
        
        search_in_content = kwargs.get("search", None)
        file_paths = self.get_comp_factory().search_comprehension_files(folder_path,
                                                                        search_in_name = search,
                                                                        search_in_content = search_in_content)

        file_path = random.choice(file_paths)
        
        return self.get_comp_factory().PROBLEM_TEMPLATE_COMP_RANDOM_QUESTIONS(file_path, *args, **kwargs)

    
    def _problem_night_vision_goggles(self, *args, **kwargs):
        folder_path = "comprehension/physics/interesting_physics"
        search = "night_vision_goggles.txt"
        
        search_in_content = kwargs.get("search", None)
        file_paths = self.get_comp_factory().search_comprehension_files(folder_path,
                                                                        search_in_name = search,
                                                                        search_in_content = search_in_content)

        file_path = random.choice(file_paths)
        
        return self.get_comp_factory().PROBLEM_TEMPLATE_COMP_RANDOM_QUESTIONS(file_path, *args, **kwargs)

    
    def _problem_the_men_who_promised_the_impossible_unlimited_energy(self, *args, **kwargs):
        folder_path = "comprehension/physics/interesting_physics"
        search = "the_men_who_promised_the_impossible_unlimited_energy.txt"
        
        search_in_content = kwargs.get("search", None)
        file_paths = self.get_comp_factory().search_comprehension_files(folder_path,
                                                                        search_in_name = search,
                                                                        search_in_content = search_in_content)

        file_path = random.choice(file_paths)
        
        return self.get_comp_factory().PROBLEM_TEMPLATE_COMP_RANDOM_QUESTIONS(file_path, *args, **kwargs)

    
