'''
Created on 02-Mar-2021

@author: bthakur
'''
'''
Created on 07-Feb-2021

@author: bthakur
'''
import numpy as np
import random
import inspect
import traceback

from sympy import (simplify, sympify, log, latex, Symbol, symbols, 
                   UnevaluatedExpr as ueval)

from xv.km.util import latex_fraction
from xv.km.kelements import KPrintElement
        
from ..helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate

# _grade9_manager
# Grade9Manager
        
class Grade9Manager(BaseManager):
    '''
    LCM
    Example:
        ke = Grade9Manager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ke.getRandomProblem(problem_type = 1)
        ...
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()

        ke.printProblemTypes()
    '''    
    def __new__(cls, *args, **kwargs):
        instance = super(Grade9Manager, cls).__new__(cls, *args, **kwargs)
        for base_class in Grade9Manager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass

    def _TEMPLATE_CUSTOM_QUESTIONS(self, keywords, **kwargs):
        
        from ..storeddata import Grade9StoredQuestions
        
        stored_questions = Grade9StoredQuestions(verbose = self.verbose)
        result = stored_questions.get_random_question(keywords)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        if result is None:
            prob_s = f"""
            Failed to get questions
            keywords = {keywords}
            """
            problemTemplate.add_problem(prob_s.strip(), 'text/html')
            return problemTemplate
            
        
        prob_s = f"""
        {result['prob_s']}
        """
        problemTemplate.add_problem(prob_s.strip(), '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 _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_custom_questions_percentage',
            '_problem_custom_questions_algebric_equation',
            '_problem_custom_questions_abscissa_ordinate',
            '_problem_custom_questions_simplify',
            '_problem_custom_questions_factorize',
            '_problem_custom_questions_angles',
            '_problem_custom_questions_coordinate_system',
            '_problem_custom_questions_comparision',
            '_problem_custom_questions_algebric_equation_1',
            '_problem_custom_questions_irrational',
            '_problem_custom_questions_area_triangle',
            '_problem_custom_questions_congruent_triangle',
            '_problem_custom_questions_simplify_1',
            '_problem_custom_questions_simplified_fraction',
            '_problem_custom_questions_simplified_fraction_1',
            '_problem_custom_questions_mode',
            '_problem_custom_questions_root',
            '_problem_custom_questions_volume_cone',
            '_problem_custom_questions_probability',
            '_problem_custom_questions_polynomials',
            '_problem_custom_questions_graph',
            '_problem_custom_questions_right_triangle',
            '_problem_custom_questions_factor_polynomial',
            '_problem_custom_questions_polynomial_value',

                    
         ]) 
        pass

    def _problem_custom_questions_percentage(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'percentage')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_algebric_equation(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'algebric_equation')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_abscissa_ordinate(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'abscissa_ordinate')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_simplify(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'simplify')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_factorize(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'factorize')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_angles(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'angles')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_coordinate_system(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'coordinate_system')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_comparision(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'comparision')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_algebric_equation_1(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'algebric_equation_1')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_irrational(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'irrational')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_area_triangle(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'area_triangle')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_congruent_triangle(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'congruent_triangle')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_simplify_1(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'simplify_1')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_simplified_fraction(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'simplified_fraction')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_simplified_fraction_1(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'simplified_fraction_1')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_mode(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'mode')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_root(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'root')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_volume_cone(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'volume_cone')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_probability(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'probability')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_polynomials(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'polynomials')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_graph(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'graph')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_right_triangle(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'right_triangle')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_factor_polynomial(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'factor_polynomial')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_polynomial_value(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'polynomial_value')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)



