from application.interactor import NCouponInteractor
from custom_sysactions import user_authorized_to_execute_action

from msgbus import TK_SYS_ACK
from mw_helper import show_message_dialog
from sysactions import (
    action,
    StopAction,
)

from typing import List


@action
def remove_applied_benefit_on_payment(
    pos_id,         # type: str
    coupon_ids,     # type: str
):
    # type: (...) -> None

    NCouponInteractor.remove_benefits(
        pos_id=pos_id,
        benefit_keys=[coupon_ids],
    )


@user_authorized_to_execute_action
def remove_discounts(
    pos_id,     # type: str
    coupon_ids  # type: List[str]
):
    # type: (...) -> None

    msg = NCouponInteractor.remove_benefits(
        pos_id=pos_id,
        benefit_keys=coupon_ids,
    )
    if msg.token != TK_SYS_ACK:
        show_message_dialog(
            pos_id=pos_id,
            title="$ERROR",
            message=msg.data,
        )
        raise StopAction()
