from sysactions import action

from .common_lock import (
    acquire_user_lock,
    release_user_lock,
)
from .. import logger
from ..models import UserLockType


@action
def acquire_user_lock_performing_tender_action(
    pos_id,             # type: str
    user_id,            # type: str
):
    # type: (...) -> bool

    log_message = "Acquire user lock performing tender action POS: {} - User: {}"
    logger.debug(log_message.format(pos_id, pos_id))
    three_minutes = 60 * 3
    return acquire_user_lock(
        user_id=user_id,
        lock_reason=UserLockType.PERFORMING_TENDER,
        lock_timeout=three_minutes
    )


@action
def release_user_lock_action(
    pos_id,     # type: str
    user_id,    # type: str
):
    # type: (...) -> None

    logger.debug("Release user lock action POS: {} - User: {}".format(pos_id, user_id))
    release_user_lock(
        user_id=user_id,
    )


def acquire_user_lock_close_operator(
    user_id,    # type: str
):
    # type: (...) -> bool

    return acquire_user_lock(
        user_id=user_id,
        lock_reason=UserLockType.CLOSING_OPERATOR,
    )
