# -*- coding: utf-8 -*-
import sysactions

from actions.login.common_lock import release_user_lock
from actions.login.get_lock_message import get_lock_message
from actions.login.lock_user_actions import acquire_user_lock_close_operator
from actions.login.utils import login_user


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

    if not acquire_user_lock_close_operator(user_id=user_id):
        sysactions.show_messagebox(
            posid=pos_id,
            message=get_lock_message(user_id=user_id),
            icon="warning",
        )
        raise sysactions.StopAction()

    try:
        return login_user(pos_id, user_id)
    finally:
        release_user_lock(user_id=user_id)
