import inspect
import traceback

import random
import sympy as sp
from ._base_subtract_q_gen import BaseSubtractQGen

class SubtractFracQGen(BaseSubtractQGen):
    """
    Subtraction question generator for fractions, with full, step-by-step LaTeX solutions.
    Uses sympy's Rational everywhere for math and LaTeX.
    """

    def __init__(self, min_value=1, max_value=10, max_denominator=12, **kwargs):
        super().__init__(min_value, max_value, **kwargs)
        self.max_denominator = max_denominator

    def _init_swp_templates(self):
        from ._subtract_frac_word_prob_templates import SubtractFracWordProbTemplates
        swp_templates = SubtractFracWordProbTemplates(self)
        return swp_templates
        pass



    def _rand_fraction(self):
        numerator = random.randint(self.min_value, self.max_value)
        denominator = random.randint(2, self.max_denominator)
        return sp.Rational(numerator, denominator)

    def _rand_pair(self):
        a = self._rand_fraction()
        b = self._rand_fraction()
        if a < b:
            a, b = b, a
        return a, b

