'''
Created on 16-Apr-2021

@author: rishi_priyansh
'''
import os 
import numpy as np
import random
import inspect
import traceback

from sympy import latex

from xv.km.ui import SvgHelper         
from ..helper import BaseHelper

from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
        
class GaussLawManager(BaseManager):
    '''
    Circle and its geometry
    Example:
        ke = GaussLawManager()
        ke
        
        ke.printProblemTypes()
        
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ke.getRandomProblem(problem_type = 1)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printLength(2, 5, 3, -1)
        ke.printMovementLengths()        
        
        
    '''    
    def __new__(cls, *args, **kwargs):
        instance = super(GaussLawManager, cls).__new__(cls, *args, **kwargs)
        for base_class in GaussLawManager.__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_guass_law_electric',
            '_problem_guass_law_magnetic',
            '_problem_guass_law_gravity',
         ])
        pass


    def _problem_guass_law_electric(self, *args, **kwargs):
        ffh = self.base_helper.get_force_field_helper()

    def _problem_overview(self, *args, **kwargs):
        glh = self.base_helper.get_gauss_law_helper()
        
        result = glh.get_gauss_law()

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

        problem_s = f"""
        
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle \\Phi_{{E}}=\\frac{{Q}}{{\\varepsilon_{{0}}}}$

        $\\displaystyle \\Phi_{{E}}= \\oint\\oint_{{S}} \\mathbf{{E}} \\cdot \\mathrm{{d}} \\mathbf{{A}}$

        $\\displaystyle \\Phi_{{E}}= c \\oint\\oint_{{S}} F^{{\\kappa 0}} \\sqrt{{-g}} \\mathrm{{~d}} S_{{\\kappa}}$                
        
        =======================

        $\\displaystyle \\nabla \\cdot \\mathbf{{E}}=\\frac{{\\rho}}{{\\varepsilon_{{0}} \\varepsilon_{{r}}}}$

        ==========================

        $\\displaystyle \\oint\\oint_{{S}} \\mathbf{{E}} \\cdot \\mathrm{{d}} \\mathbf{{A}} = \\frac{{Q}}{{\\varepsilon_{{0}}}}$

        $\\displaystyle \\iiint_{{V}} \\nabla \\cdot \\mathbf{{E}} \\mathrm{{d}} \\mathbf{{V}} = \\frac{{Q}}{{\\varepsilon_{{0}}}}$
        
        $\\displaystyle \\iiint_{{V}} \\nabla \\cdot \\mathbf{{E}} \\mathrm{{d}} \\mathbf{{V}} = \\iiint_{{V}} \\frac{{\\rho}}{{\\varepsilon_{{0}}}} \\mathrm{{d}} \\mathbf{{V}}$

        $\\displaystyle \\nabla \\cdot \\mathbf{{E}}=\\frac{{\\rho}}{{\\varepsilon_{{0}}}}$
        
        ==========================

        

        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_guass_law_magnetic(self, *args, **kwargs):
        ffh = self.base_helper.get_force_field_helper()

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

        problem_s = f"""
        
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle \\Phi_{{E}}=\\frac{{Q}}{{\\varepsilon_{{0}}}}$

        $\\displaystyle \\Phi_{{E}}= \\oint\\oint_{{S}} \\mathbf{{E}} \\cdot \\mathrm{{d}} \\mathbf{{A}}$

        $\\displaystyle \\Phi_{{E}}= c \\oint\\oint_{{S}} F^{{\\kappa 0}} \\sqrt{{-g}} \\mathrm{{~d}} S_{{\\kappa}}$                
        
        $\\displaystyle \\nabla \\cdot \\mathbf{{E}}=\\frac{{\\rho}}{{\\varepsilon_{{0}} \\varepsilon_{{r}}}}$

        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_guass_law_gravity(self, *args, **kwargs):
        ffh = self.base_helper.get_force_field_helper()

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

        problem_s = f"""
        
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle \\Phi_{{E}}=\\frac{{Q}}{{\\varepsilon_{{0}}}}$

        $\\displaystyle \\Phi_{{E}}= \\oint\\oint_{{S}} \\mathbf{{E}} \\cdot \\mathrm{{d}} \\mathbf{{A}}$

        $\\displaystyle \\Phi_{{E}}= c \\oint\\oint_{{S}} F^{{\\kappa 0}} \\sqrt{{-g}} \\mathrm{{~d}} S_{{\\kappa}}$                
=======
        <h2></h2>
        $\\displaystyle {latex(result['eq'])}$
        
        $\\displaystyle \\implies {latex(result['eq_gauss_gross'])}$
        
        $\\displaystyle \\implies {latex(result['eq_gauss'])}$
        
        
        
        $\\displaystyle \\nabla \\cdot \\mathbf{{E}}=\\frac{{\\rho}}{{\\varepsilon_{{0}} \\varepsilon_{{r}}}}$

        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

#class GaussLawManager
