"""
Money arithmetic for Munal LMS.

All NPR amounts are quantized to 2 decimal places (paisa) with commercial
ROUND_HALF_UP rounding at every step (discounts, totals, payments). This keeps
the frontend preview, the bill ledger, and the payment ledger bit-identical so
partial-paisa residues (e.g. NPR 0.50 dues after a "full" payment) cannot occur.
"""

from decimal import ROUND_HALF_UP, Decimal

CENT = Decimal("0.00")


def npr(amount: Decimal) -> Decimal:
    """Quantize any Decimal to whole paisa (2dp, commercial half-up)."""
    if not isinstance(amount, Decimal):
        amount = Decimal(str(amount))
    return amount.quantize(Decimal("0.00"), rounding=ROUND_HALF_UP)
