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

# _laplace_transform_manager
# LaplaceTransformManager

class LaplaceTransformManager(BaseManager):
    '''
    Tranformation of function

    Example:
        ke = LaplaceTransformManager()
        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(LaplaceTransformManager, cls).__new__(cls, *args, **kwargs)
        for base_class in LaplaceTransformManager.__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_laplace_transform',
                '_problem_laplace_transform_questions',

             ])
        pass

    def _problem_overview_laplace_transform(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        lt_helper = self.base_helper.get_algebra_helper().get_laplace_transform_helper()
        result = lt_helper.get_problem_overview_laplace_transform(**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



    def _problem_laplace_transform_questions(self, *args, **kwargs):
        """

        """

        folder_path = "question_bank/math/calculus"
        search_file_paths = [
                "laplace_transform_questions.txt"
            ]

        file_paths = self.get_q_bank_factory().search_question_bank_files(folder_path, search_file_paths)
        return self.get_q_bank_factory().PROBLEM_TEMPLATE_Q_BANK_RANDOM_QUESTION(file_paths, *args, **kwargs)


