from typing import Union
from xml.etree import cElementTree as eTree

from sysactions import get_user_information

from model.customexception import NotFoundUserError


def get_operator_name(
        user_id  # type: Union[int, str]
):
    # type: (...) -> Union[str, None]
    if user_id is None:
        return None

    user_xml_str = get_user_information(user_id)
    if user_xml_str is None:
        raise NotFoundUserError("USER_NOT_FOUND")

    user_xml = eTree.XML(user_xml_str)
    user_element = user_xml.find("user")

    return user_element.get("LongName")
