'''
Created on 24-Jul-2025

@author: bthakur
'''

from ._base_subtract_word_prob_templates import BaseSubtractWordProbTemplates

# SubtractDecWordProbTemplates
# _subtract_dec_word_prob_templates

class SubtractDecWordProbTemplates(BaseSubtractWordProbTemplates):
    """
    20 competition-style, high-quality subtraction word problem templates.
    Each method takes (a, b) and returns (question, explanation).
    All problems reduce to a direct subtraction (a - b).
    Suitable for international-level and creative practice.
    """

    def __init__(self, gen_cls, **kwargs):
        # Call parent constructor and set generator type
        super().__init__(gen_cls, **kwargs)



    def chocolate_sharing(self, a, b):
        """
        Alice takes one-third of the chocolates (can be decimal) and gives b of those to Bob.
        Find how many chocolates are left in the box.
        """
        one_third = a / 3
        chocolates_left = self.cal_result(a, one_third, '-')
        left_by_alice = self.cal_result(one_third, b, '-')

        sp_a = self.sp_latex(a)
        sp_b = self.sp_latex(b)
        sp_one_third = self.sp_latex(one_third)
        sp_left_by_alice = self.sp_latex(left_by_alice)
        sp_chocolates_left = self.sp_latex(chocolates_left)

        question = (
            f"A box contains <b>${sp_a}$</b> chocolates. Alice takes one-third of them and gives <b>${sp_b}$</b> to Bob. "
            f"How many chocolates are left in the box?"
        )
        explanation = (
            f"Alice takes 1/3 of <b>${sp_a}$</b> = <b>${sp_one_third}$</b>.<br>"
            f"She gives <b>${sp_b}$</b> to Bob, so she keeps <b>${sp_left_by_alice}$</b>.<br>"
            f"Chocolates left in the box: <b>${sp_a}$</b> − <b>${sp_one_third}$</b> = <b>${sp_chocolates_left}$</b>."
        )
        return question, explanation



    def school_contest(self, a, b):
        """
        Total students: a, left after first round: b.
        Then, half of the remaining students left again (allows decimals).
        """
        after_first = self.cal_result(a, b, '-')
        final = after_first / 2

        sp_a = self.sp_latex(a)
        sp_b = self.sp_latex(b)
        sp_after_first = self.sp_latex(after_first)
        sp_final = self.sp_latex(final)

        question = (
            f"There are <b>${sp_a}$</b> students in a contest. <b>${sp_b}$</b> left after the first round. "
            f"Then, half of the remaining students left again. How many students stayed till the end?"
        )
        explanation = (
            f"Remaining after first round: ${sp_a}$ − ${sp_b}$ = <b>${sp_after_first}$</b>.<br>"
            f"Half of those left again, so remaining = <b>${sp_after_first}$</b> ÷ 2 = <b>${sp_final}$</b>."
        )
        return question, explanation


    def split_apples(self, a, b):
        """
        A juice shop has a liters of apple juice. They serve 1/4 of it to Tom and b liters to Mary. Find how much is left.
        """
        tom = a / 4
        remain_after_tom = self.cal_result(a, tom, '-')
        left = self.cal_result(remain_after_tom, b, '-')

        sp_a = self.sp_latex(a)
        sp_b = self.sp_latex(b)
        sp_tom = self.sp_latex(tom)
        sp_remain_after_tom = self.sp_latex(remain_after_tom)
        sp_left = self.sp_latex(left)

        gen_cls = self.get_gen_cls()
        _, _, _, subtract_block_1 = gen_cls.align_and_subtract_block(a, tom, with_steps=False)
        _, _, _, subtract_block_2 = gen_cls.align_and_subtract_block(remain_after_tom, b, with_steps=False)

        question = (
            f"A juice shop has <b>${sp_a}$</b> liters of apple juice. They serve one-fourth of it to Tom, "
            f"and then serve <b>${sp_b}$</b> liters to Mary. How much juice is left?"
        )

        explanation = (
            f"Tom gets 1/4 of <b>${sp_a}$</b> = <b>${sp_tom}$</b> liters.<br>"
            f"Remaining after Tom’s share: <b>${sp_a}$ − ${sp_tom}$ = ${sp_remain_after_tom}$</b> liters.<br>"
            f"{subtract_block_1}<br>"
            f"After serving Mary: <b>${sp_remain_after_tom}$ − ${sp_b}$ = ${sp_left}$</b> liters left.<br>"
            f"{subtract_block_2}"
        )
        return question, explanation


