'''
Created on 16-Oct-2023

@author: bthakur
'''
import inspect
import traceback

from xv.km.ui import SvgHelper         

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

import numpy as np
import sympy as sp

# _triangle_manager
# TriangleManager
        
class TriangleManager(BaseManager):
    '''
    Circle and its geometry
    Example:
        ke = TriangleManager()
        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(TriangleManager, cls).__new__(cls, *args, **kwargs)
        for base_class in TriangleManager.__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_triangle_basic_properties',
            '_problem_computation_given_three_sides',
            '_problem_computation_sides_to_coordinates',
            
         ])
        pass


    def _problem_triangle_basic_properties(self, *args, **kwargs):
        triangle_helper = self.base_helper.get_geometry_helper().get_triangle_helper()

        result = triangle_helper.get_triangle_basic_properties()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        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 _problem_computation_given_three_sides(self, *args, **kwargs):
        triangle_helper = self.base_helper.get_geometry_helper().get_triangle_helper()

        result = triangle_helper.get_computation_given_three_sides()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        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 _problem_computation_sides_to_coordinates(self, *args, **kwargs):
        triangle_helper = self.base_helper.get_geometry_helper().get_triangle_helper()

        result = triangle_helper.get_computation_sides_to_coordinates()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        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
    


