'''
Created on 01-Apr-2021
@author: rishi_priyansh
'''

from sympy import ( Eq,
                    Limit,
                    Pow, Mul, Add, exp,
                    Function, latex, Integral, solve, 
                    UnevaluatedExpr, S, oo, log, logcombine)


import numpy as np
import random
import inspect
import traceback
from sympy import (symbols, Symbol)

from xv.km.util import latex_fraction, latex_atom
from ...helper import BaseHelper

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

# _gas_law_manager
# GasLawManager

        
class GasLawManager(BaseManager):
    '''
    Gas Laws
    Example:
        ke = GasLawManager()
        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(GasLawManager, cls).__new__(cls, *args, **kwargs)
        for base_class in GasLawManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        pass

    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
                'problem_sample',
             ])
        pass

    def problem_sample(self, *args, **kwargs):
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        prob_s = f"""
        Define ideal gas law
        """
        problemTemplate.add_problem(prob_s.strip(), 'text/html')
        
        soln_s = f'''
        The ideal gas law is an equation of state the describes the behavior of an ideal gas and also a real gas under conditions of ordinary temperature and low pressure. This is one of the most useful gas laws to know because it can be used to find pressure, volume, number of moles, or temperature of a gas.
        
        
        The formula for the ideal gas law is:
        
        PV = nRT
        
        P = pressure
        V = volume
        n = number of moles of gas
        R = ideal or universal gas constant = 0.08 L atm / mol K
        T = absolute temperature in Kelvin
        
        Sometimes, you may use another version of the ideal gas law:
        
        PV = NkT
        
        where:
        
        N = number of molecules
        k = Boltzmann constant = 1.38066 x 10-23 J/K = 8.617385 x 10-5 eV/K
        
        Ideal Gas Law Example
        One of the easiest applications of the ideal gas law is to find the unknown value, given all the others.
        
        6.2 liters of an ideal gas is contained at 3.0 atm and 37 °C. How many moles of this gas are present?
        
        Solution
        
        The ideal gas law states
        
        PV = nRT
        
        Because the units of the gas constant are given using atmospheres, moles, and Kelvin, it's important to make sure you convert values given in other temperature or pressure scales. For this problem, convert °C temperature to K using the equation:
        
        T = °C + 273
        
        T = 37 °C + 273
        T = 310 K
        
        Now, you can plug in the values. Solve ideal gas law for the number of moles
        
        n = PV / RT
        
        n = ( 3.0 atm x 6.2 L ) / ( 0.08 L atm /mol K x 310 K)
        n = 0.75 mol
        
        Answer
        
        There are 0.75 mol of the ideal gas present in the system.
        '''
        problemTemplate.add_solution(soln_s.strip(), 'text/html')

        answer_s = f'''
        {soln_s}
        '''
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        
        return problemTemplate
        pass

        