import os

import cfgtools

min_level_to_open_qsr_operator = None
min_level_to_open_ts_operator = None


def get_min_level_to_open_operator(
        user_control_type   # type: str
):
    # type: (...) -> int

    global min_level_to_open_qsr_operator, min_level_to_open_ts_operator

    if user_control_type.upper() == "QSR":
        if min_level_to_open_qsr_operator is None:
            config = cfgtools.read(os.environ["LOADERCFG"])
            min_level = config.find_value("Customizations.MinLevelOpenOperator.QSR")
            min_level_to_open_qsr_operator = int(min_level) + 1 if min_level is not None else 10

        return min_level_to_open_qsr_operator

    if user_control_type.upper() == "TS":
        if min_level_to_open_ts_operator is None:
            config = cfgtools.read(os.environ["LOADERCFG"])
            min_level = config.find_value("Customizations.MinLevelOpenOperator.TS")
            min_level_to_open_ts_operator = int(min_level) + 1 if min_level is not None else 0

        return min_level_to_open_ts_operator
