from __future__ import annotations

from decimal import Decimal, ROUND_HALF_UP
from typing import Any

UGX_QUANTUM = Decimal("1")


def as_decimal(value: Any) -> Decimal:
    if isinstance(value, Decimal):
        return value
    if value is None:
        return Decimal("0")
    return Decimal(str(value))


def money(value: Any) -> Decimal:
    return as_decimal(value).quantize(UGX_QUANTUM, rounding=ROUND_HALF_UP)
