'''
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 ...helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate

# _set_theory_manager
# SetTheoryManager
        
class SetTheoryManager(BaseManager):
    '''
    LCM
    Example:
        ke = SetTheoryManager()
        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(SetTheoryManager, cls).__new__(cls, *args, **kwargs)
        for base_class in SetTheoryManager.__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_plot_venn_diagram',
            '_problem_set_properties',
            '_problem_identify_a_group',
            '_problem_identify_an_abelian_group',
            '_problem_lagrange_s_theorem_of_subgroup',
            '_problem_prove_example_subgroup_and_lagrange_s_theorem',
            '_problem_identify_a_ring',
            '_problem_identify_a_field',
            '_problem_identify_a_vector_space',
            #'_problem_TEMP',
            #'_problem_TEMP',
            #'_problem_TEMP',
            #'_problem_TEMP',
            #'_problem_TEMP',
            #'_problem_TEMP',
            #'_problem_TEMP',
            
         ])
        pass

    def _problem_plot_venn_diagram(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        svg_str, plot_code = st_helper.plot_venn_diagram()


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

        
        prob_s = f"""
        Plot a sample venn diagram.


        """
        problemTemplate.add_problem(prob_s.strip(), "text/html")
        
        soln_s = f"""
        <b>Sample venn diagram:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot the sample venn diagram:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate
    

    def _problem_set_properties(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_set_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/plane')
        return problemTemplate
        
        pass

    
    def _problem_identify_a_group(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_identify_a_group()


        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/plane')
        return problemTemplate
        
        pass

    
    def _problem_identify_an_abelian_group(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_identify_an_abelian_group()


        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/plane')
        return problemTemplate
        
        pass

    
    def _problem_lagrange_s_theorem_of_subgroup(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_lagrange_s_theorem_of_subgroup()


        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/plane')
        return problemTemplate
        
        pass


    def _problem_prove_example_subgroup_and_lagrange_s_theorem(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_prove_example_subgroup_and_lagrange_s_theorem()


        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/plane')
        return problemTemplate
        
        pass


    def _problem_identify_a_ring(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_identify_a_ring()


        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/plane')
        return problemTemplate
        
        pass



    def _problem_identify_a_field(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_identify_a_field()


        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/plane')
        return problemTemplate
        
        pass


    def _problem_identify_a_vector_space(self, *args, **kwargs):
        st_helper = self.base_helper.get_stats_helper().get_set_theory_helper()
        result = st_helper.get_problem_identify_a_vector_space()


        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/plane')
        return problemTemplate
        
        pass




    pass
