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

from actions.login.signout_user import sign_out_user
from actions.util.list_users import get_opened_users


@sysactions.action
def close_operators(pos_id):
    model = sysactions.get_model(pos_id)
    sysactions.check_current_order(pos_id, model=model, need_order=False)

    pos_to_close_user, user, operator = get_opened_users(pos_id=pos_id)

    if user is None:
        return False

    return sign_out_user(
        pos_id=pos_id,
        user_id=user.get("id"),
        pos_to_close_user=pos_to_close_user,
    )
