# TODO: add typings
# TODO: add unit tests
def matchHpHealing(healing, statusBar):
    if healing.get('hpLessThanOrEqual') is not None:
        return statusBar.get('hp') is not None and statusBar['hp'] <= healing['hpLessThanOrEqual']
    if healing.get('hpPercentageLessThanOrEqual') is not None:
        if statusBar['hpPercentage'] > healing['hpPercentageLessThanOrEqual']:
            return False
    if healing.get('manaPercentageGreaterThanOrEqual') is not None:
        if statusBar['hpPercentage'] < healing['manaPercentageGreaterThanOrEqual']:
            return False
    return True


# TODO: add typings
# TODO: add unit tests
def matchManaHealing(healing, statusBar):
    if healing['manaPercentageLessThanOrEqual'] is None:
        return False
    if statusBar['manaPercentage'] > healing['manaPercentageLessThanOrEqual']:
        return False
    return True


def healthPotionTakesPriority(context):
    """True, wenn der Heiltrank greifen sollte (Zauber muessen warten)."""
    potion = context['healing']['potions']['firstHealthPotion']
    if not potion.get('enabled'):
        return False
    return matchHpHealing(potion, context['ng_statusBar'])
