import logging

import sysactions

from actions.eft import confirm_finish_eft_transactions

logger = logging.getLogger("EftActions")


@sysactions.action
def confirm_cancel_eft_mobile_transactions(
    pos_id,             # type: str
    data,               # type: str
    result_code=None,   # type: str
    message=None        # type: str
):
    # type: (...) -> None

    try:
        if not data or result_code != "0":
            error = "Error confirm cancel eft mobile transactions: {} | {} | {}".format(result_code, message, data)
            logger.error(error)
            confirm_finish_eft_transactions(
                pos_id=pos_id,
                status="0",
            )
            return

        logger.debug("Success cancel transactions mobile: {0}".format(data))
        confirm_finish_eft_transactions(
            pos_id=pos_id,
            status="1",
            data=data,
        )
    except Exception as _:
        logger.exception("Error cancel transactions mobile: {0}".format(data))
        confirm_finish_eft_transactions(
            pos_id=pos_id,
            status="0",
        )
