'''
Created on 13-Aug-2024
@author: Rishi
'''
import random
import inspect
import traceback

from sympy.core.expr import UnevaluatedExpr

from sympy import ( latex, solve, simplify, 
                    pi, Rational,
                    exp, sin, cos, tan,
                    asin, acos, atan,
                    sinh, cosh, tanh,
                    log, exp, sqrt,
                    Eq,
                    symbols, Symbol, Function,
                    UnevaluatedExpr as ueval
                    )
import sympy
from numpy import linspace

from xv.util import number_to_nth, list_to_str
from xv.util import run_with_timeout

from ...helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
        
# _gamma_func_manager        
# GammaFuncManager        
        
class GammaFuncManager(BaseManager):
    '''
    Tranformation of function
    
    Example:
        ke = GammaFuncManager()
        ke
        
        ke.setTerms(5) #number of terms in polynomial
        
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ke.getRandomProblem(problem_type = 1)
        ...
        ke.get_polynomial()
        ke.printPolynomial()
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
                
        
    '''    
    def __new__(cls, *args, **kwargs):
        instance = super(GammaFuncManager, cls).__new__(cls, *args, **kwargs)
        for base_class in GammaFuncManager.__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_overview_gamma_function',
             ])
        pass
    
    def _problem_overview_gamma_function(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        gf_helper = self.base_helper.get_algebra_helper().get_gamma_func_helper()
        result = gf_helper.get_problem_overview_gamma_function(**kwargs)
              
        prob_s = f""" 
        {result['prob_s']}
        
        """
        problemTemplate.add_problem(prob_s, "text/html")

        soln_s = f"""
        {result['soln_s']}
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')

        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
        pass

