
from .utils_auth import LicenseInformationModel, getLicenses
from .utils_debug import debug_err
from .settings_addon import getAddonPreferences


def __getLicense() -> LicenseInformationModel | None:
    license = getLicenses()
    if not license: return None
    return license

def getLicenseIsActive() -> bool:
    license = getLicenses()
    if not license: return False
    return license.needle_engine_license_is_active

def hasLicense():
    '''
    Check if the user has a commercial license.
    '''
    license = __getLicense()
    if not license: return False
    if not hasattr(license, "needle_engine_license_is_active"): return False
    if not license.needle_engine_license_is_active: return False
    licenseName = license.needle_engine_license
    return licenseName == "indie" or licenseName == "pro" or licenseName == "enterprise"

def hasIndieLicense():
    license = __getLicense()
    if not license: return False
    if not hasattr(license, "needle_engine_license_is_active"): return False
    if not license.needle_engine_license_is_active: return False
    licenseName = license.needle_engine_license
    return licenseName == "indie"

def hasProLicense():
    license = __getLicense()
    if not license: return False
    if not hasattr(license, "needle_engine_license_is_active"): return False
    if not license.needle_engine_license_is_active: return False
    licenseName = license.needle_engine_license
    return licenseName == "pro" or licenseName == "enterprise"
