'''
Created on 03-June-2024

@author: B Thakur

Space time momentum energy

'''
import random
import inspect
import traceback

from ..helper import BaseHelper

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


# _point_mass_manager
# PointMassManager


class PointMassManager(BaseManager):
    '''
    PointMassManager
    
    Example:
        ke = PointMassManager()
        ke
        
        ke.printProblemTypes()
        
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        
        
    '''    
    def __new__(cls, *args, **kwargs):
        instance = super(PointMassManager, cls).__new__(cls, *args, **kwargs)
        for base_class in PointMassManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass

        pass

    def _init_problem_types(self, *args, **kwargs):
        
        self._append_problem_types([
            '_problem_point_mass_with_position_vector',
            '_problem_point_mass_with_velocity_vector',
            '_problem_point_mass_with_acceleration_vector',
            
            '_problem_gravitation_on_point_mass',
         ])
        pass

    def _problem_point_mass_with_position_vector(self, *args, **kwargs):
        pm_helper = self.base_helper.get_point_mass_helper()
        
        result = pm_helper.get_problem_point_mass_with_position_vector()
        
        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

    def _problem_point_mass_with_velocity_vector(self, *args, **kwargs):
        pm_helper = self.base_helper.get_point_mass_helper()
        
        result = pm_helper.get_problem_point_mass_with_velocity_vector()
        
        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

    def _problem_point_mass_with_acceleration_vector(self, *args, **kwargs):
        pm_helper = self.base_helper.get_point_mass_helper()
        
        result = pm_helper.get_problem_point_mass_with_acceleration_vector()
        
        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


    def _problem_gravitation_on_point_mass(self, *args, **kwargs):
        pm_helper = self.base_helper.get_point_mass_helper()
        
        result = pm_helper.get_problem_gravitation_on_point_mass()
        
        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


