'''
Created on 26-Jan-2022
@author: bthakur
'''
import random
import inspect
import traceback
from sympy import latex

from ..helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
        
# _ratio_manager
# RatioManager

class RatioManager(BaseManager):
    '''
    Example:
        ke = RatioManager()
        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(RatioManager, cls).__new__(cls, *args, **kwargs)
        for base_class in RatioManager.__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_calculate_ratio_of_ints',
                '_problem_calculate_ratio_of_rational_numbers',
                '_problem_calculate_ratio_of_decimal_numbers',
                '_problem_calculate_ratio_of_numbers',
                '_problem_ratio_with_proportion',
                '_problem_even_odd_divisor_ratio',
             ])
        pass
    
    def _problem_calculate_ratio_of_ints(self, *args, **kwargs):
        ratio_helper = self.base_helper.get_arithmetic_helper().get_ratio_helper()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        result = ratio_helper.get_problem_calculate_ratio_of_ints(*args, **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_calculate_ratio_of_rational_numbers(self, *args, **kwargs):
        ratio_helper = self.base_helper.get_arithmetic_helper().get_ratio_helper()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        result = ratio_helper.get_problem_calculate_ratio_of_rational_numbers(*args, **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_calculate_ratio_of_decimal_numbers(self, *args, **kwargs):
        ratio_helper = self.base_helper.get_arithmetic_helper().get_ratio_helper()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        result = ratio_helper.get_problem_calculate_ratio_of_decimal_numbers(*args, **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_calculate_ratio_of_numbers(self, *args, **kwargs):
        ratio_helper = self.base_helper.get_arithmetic_helper().get_ratio_helper()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        result = ratio_helper.get_problem_calculate_ratio_of_numbers(*args, **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_ratio_with_proportion(self, *args, **kwargs):
        ratio_helper = self.base_helper.get_arithmetic_helper().get_ratio_helper()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        result = ratio_helper.get_problem_ratio_with_proportion(*args, **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_even_odd_divisor_ratio(self, *args, **kwargs):
        ratio_helper = self.base_helper.get_arithmetic_helper().get_ratio_helper()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        result = ratio_helper.get_problem_even_odd_divisor_ratio(*args, **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

