'''
Created on 22-Oct-2022

@author: bthakur


'''
import os 
import numpy as np
import random
import inspect
import traceback


from sympy import ( symbols, factor)

from xv.km.kelements import KPrintElement
        
from ..helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
from xv.util import toIntOrFloat, format_integers

# _crypto_introduction_manager
# CryptoIntroductionManager
        
class CryptoIntroductionManager(BaseManager):
    '''
    Crypto Introduction


    Minimum Grade: 3
    Maximum Grade: 12


    Examples
    --------
    ke = CryptoIntroductionManager()
    ke 
    
    ke.printProblemTypes()
    ke.helpProblemType(0)
    
    ke.getRandomProblem()
    ke.getRandomProblem(problem_type = 0)


    ke.printProblem()
    ke.printAnswer()
    ke.printSolution()


    doc_style: xv_doc
    ''' 


    def __new__(cls, *args, **kwargs):
        instance = super(CryptoIntroductionManager, cls).__new__(cls, *args, **kwargs)
        for base_class in CryptoIntroductionManager.__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_crypto_arithmetic',
                '_problem_is_crypto_arithmetic',
             ])
        pass

    def _problem_crypto_arithmetic(self, *args, **kwargs):
        """
        doc_style: xv_doc
        """
        crypto_helper = self.base_helper.get_crypto_helper()
        
        result = crypto_helper.get_random_crypto_problem(keyword = None) 

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

        problem_s = f"""
        {result['problem_s']}
        """
        problemTemplate.add_problem(problem_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_is_crypto_arithmetic(self, *args, **kwargs):
        """
        doc_style: xv_doc
        """
        crypto_helper = self.base_helper.get_crypto_helper()
        
        one_to_one = random.choice([True, False])
        result = crypto_helper.get_random_crypto_problem(keyword = None,
                                                         one_to_one = one_to_one) 

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

        problem_s = f"""
        {result['problem_s']}
        """
        problemTemplate.add_problem(problem_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 _sample(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

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

        
