import os

# .NET framework versions supported by AAComm nuget package
NET48                   = 'net48'
NET60                   = 'net6.0'
NET80                   = 'net8.0'

NET_FRAMEWORK_CHOICES   = [NET48, NET60, NET80]
TARGET_FRAMEWORKS       = ["4.8", "6.0", "8.0"]
DEFAULT_NET_FRAMEWORK   = NET48

TARGET_FOLDER           = os.path.join(os.path.dirname(__file__), 'aacommpyDownloader-main')
NUGET_EXE               = 'nuget.exe'
NUGET_EXE_PATH          = os.path.join(TARGET_FOLDER, NUGET_EXE)

# nuget dependencies
YAML_DOT_NET            = 'YamlDotNet'
SYSTEM_IO_PORTS         = 'System.IO.Ports'

AGITO_AACOMM            = 'Agito.AAComm'
AACOMM_DLL              = 'AAComm.dll'
AACOMMSERVER            = 'AACommServer'

# Dynamic paths - computed at runtime relative to this module
_MODULE_DIR             = os.path.dirname(__file__)
AACOMM_DLL_PATH         = os.path.join(_MODULE_DIR, AACOMM_DLL)
AACOMM_SERVER_EXE_PATH  = os.path.join(_MODULE_DIR, f'{AACOMMSERVER}.exe')

# Persisted .NET framework selection
NETFW_CONFIG_PATH       = os.path.join(_MODULE_DIR, '.netfw')

def get_configured_framework() -> str:
    """Read the persisted .NET framework selection, or return default."""
    try:
        with open(NETFW_CONFIG_PATH, 'r') as f:
            fw = f.read().strip()
        if fw in NET_FRAMEWORK_CHOICES:
            return fw
    except FileNotFoundError:
        pass
    return DEFAULT_NET_FRAMEWORK

def save_configured_framework(version: str) -> None:
    """Persist the selected .NET framework for runtime configuration."""
    with open(NETFW_CONFIG_PATH, 'w') as f:
        f.write(version)