import configparser
from pathlib import Path
#from serverside.consts import BASE_DIR

BASE_DIR = Path(__file__).resolve().parent.parent.parent
CONFIG_PATH = BASE_DIR / "configuration.ini"

_config = configparser.ConfigParser()
_config.read(CONFIG_PATH)

def get(section: str, key: str, fallback=None):
    try:
        return _config.get(section, key)
    except (configparser.NoSectionError, configparser.NoOptionError):
        return fallback

def get_int(section: str, key: str, fallback=None):
    try:
        return _config.getint(section, key)
    except (configparser.NoSectionError, configparser.NoOptionError, ValueError):
        return fallback

def get_float(section: str, key: str, fallback=None):
    try:
        return _config.getfloat(section, key)
    except (configparser.NoSectionError, configparser.NoOptionError, ValueError):
        return fallback

def get_bool(section: str, key: str, fallback=None):
    try:
        return _config.getboolean(section, key)
    except (configparser.NoSectionError, configparser.NoOptionError, ValueError):
        return fallback

def sections():
    return _config.sections()

def options(section: str):
    try:
        return _config.options(section)
    except configparser.NoSectionError:
        return []