'''
Created on 16-Apr-2021

@author: bthakur
'''

        
import random
import inspect
import traceback


from xv.km.util import latex_fraction

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

from xv.km.util import KmTemplateUtil

# _integration_manager
# IntegrationManager

        
class IntegrationManager(BaseManager):
    '''
    
    Example:
        ke = IntegrationManager()
        ke
        
        ke.printProblemTypes()
        
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ke.getRandomProblem(problem_type = 1)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        
    '''    
    
    
    def __new__(cls, *args, **kwargs):
        instance = super(IntegrationManager, cls).__new__(cls, *args, **kwargs)
        for base_class in IntegrationManager.__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_integration_overview_manager',
            '_problem_applied_integration_manager',
            '_problem_standard_integration_manager',
            ])
        pass



    def _problem_integration_overview_manager(self, *args, **kwargs):
        """
        @generate_notebook: Default True

        doc_style: xv_doc
        """

        sInfo = f"""Processing {self.__class__.__name__}.{inspect.stack()[0][3]}: 
        creating notebook and getting problem from DifferentiationOverviewManager
        """
        self._log(sInfo.strip())
        
        
        #create notebook
        generate_notebook = kwargs.get('generate_notebook', True)
        
        if generate_notebook:
            saveToFolder = f"integration"
            KmTemplateUtil.CREATE_MANAGER_NOTEBOOK("xv.math.calculus", 
                                                   "DifferentiationOverviewManager", 
                                                   saveToFolder = saveToFolder,
                                                   overwrite = False, 
                                                   verbose = self.verbose)

        #get a problem        
        from xv.math.calculus import DifferentiationOverviewManager
        kwargs['manager_class'] = DifferentiationOverviewManager
        kwargs['problem_type'] = None
        kwargs['generate_notebook'] = False
        problemTemplate = self._get_problem_from_a_manager(*args, **kwargs)
        return problemTemplate

        pass




    def _problem_standard_integration_manager(self, *args, **kwargs):
        """
        @generate_notebook: Default True

        doc_style: xv_doc
        """

        sInfo = f"""Processing {self.__class__.__name__}.{inspect.stack()[0][3]}: 
        creating notebook and getting problem from StandardIntegrationManager
        """
        self._log(sInfo.strip())
        
        
        #create notebook
        generate_notebook = kwargs.get('generate_notebook', True)
        
        if generate_notebook:
            saveToFolder = f"integration"
            KmTemplateUtil.CREATE_MANAGER_NOTEBOOK("xv.math.calculus", 
                                                   "StandardIntegrationManager", 
                                                   saveToFolder = saveToFolder,
                                                   overwrite = False, 
                                                   verbose = self.verbose)

        #get a problem        
        from xv.math.calculus import StandardIntegrationManager
        kwargs['manager_class'] = StandardIntegrationManager
        kwargs['problem_type'] = None
        kwargs['generate_notebook'] = False
        problemTemplate = self._get_problem_from_a_manager(*args, **kwargs)
        return problemTemplate

        pass



    def _problem_applied_integration_manager(self, *args, **kwargs):
        """
        @generate_notebook: Default True

        doc_style: xv_doc
        """

        sInfo = f"""Processing {self.__class__.__name__}.{inspect.stack()[0][3]}: 
        creating notebook and getting problem from AppliedIntegrationManager
        """
        self._log(sInfo.strip())
        
        
        #create notebook
        generate_notebook = kwargs.get('generate_notebook', True)
        
        if generate_notebook:
            saveToFolder = f"integration"
            KmTemplateUtil.CREATE_MANAGER_NOTEBOOK("xv.math.calculus", 
                                                   "AppliedIntegrationManager", 
                                                   saveToFolder = saveToFolder,
                                                   overwrite = False, 
                                                   verbose = self.verbose)

        #get a problem        
        from xv.math.calculus import AppliedIntegrationManager
        kwargs['manager_class'] = AppliedIntegrationManager
        kwargs['problem_type'] = None
        kwargs['generate_notebook'] = False
        problemTemplate = self._get_problem_from_a_manager(*args, **kwargs)
        return problemTemplate

        pass


