from xml.etree import cElementTree as eTree
from typing import Optional

from sysactions import format_amount


def check_change_limit_error(
    model,          # type: eTree.Element
    change,         # type: float
    change_limit,   # type: float
):
    # type: (...) ->  Optional[str]

    if change < change_limit:
        return None

    if change_limit > 0:
        change_limit_amount = format_amount(
            model=model,
            amount=change_limit,
        )
        change_amount = format_amount(
            model=model,
            amount=change,
        )
        return "$MAXIMUM_CHANGE_ALLOWED|{}|{}".format(change_limit_amount, change_amount)

    return "$AMOUNT_GREATER_THAN_DUE"
