from typing import (
    Tuple,
)
from xml.etree import cElementTree as eTree  # noqa


def get_operator_info(
    model,                      # type: eTree
    operator_id,                # type: str
):
    # type: (...) -> Tuple[bool, str]

    need_logged = True
    session = ''
    for op in model.find('Operators').findall('Operator'):
        if op.get('id') == operator_id:
            operator = op
            session = operator.get('sessionId')
            if op.get('state') == 'PAUSED':
                need_logged = False
            break

    return need_logged, session


def is_current_operator_opened(
    model,                      # type: eTree
):
    # type: (...) -> bool

    return get_current_operator_session(model) in ["LOGGEDIN", "OPENED", "PAUSED"]


def get_current_operator_session(
    model,                      # type: eTree
):
    # type: (...) -> str

    model_operator = model.find('Operator')
    if not model_operator:
        return ''

    return model_operator.get('sessionId')


def get_current_state_session(
    model,                      # type: eTree
):
    # type: (...) -> str

    model_operator = model.find('Operator')
    if not model_operator:
        return ''

    return model_operator.get('state')
