# Path: config_loader.py
# def chain_load_setting(config_file_option, envvar, default):
#     # Settings file order (last wins)
#     # 1. Default
#     # 2. Settings file
#     # 3. Env var
# 
#     # 1
#     value = default
# 
#     # 2
#     _conf_value = get_option_config_file(config_file_option)
#     if _conf_value is not None:  # valid _conf_value could be Falsey
#         value = _conf_value
# 
#     # 3
#     value = os.getenv(envvar, value)
# 
#     return value


import os
import random
import redis
import string
import tempfile
from easyos import easyos
from config_loader import chain_load_setting
    from version import version
from config_plugins import *


class APP:

    LISTEN_HOST = chain_load_setting("APP_HOST", "YAMS_APP_HOST", "127.0.0.1")
    LISTEN_PORT = chain_load_setting("APP_PORT", "YAMS_APP_PORT", default=1110)
    LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)

    DEBUG = chain_load_setting("DEBUG", "YAMS_DEBUG", True)
    DEBUG_FRONTEND = chain_load_setting("DEBUG_FRONTEND", "YAMS_DEBUG_FRONTEND", False)

    API_VERSION_CORE = chain_load_setting("API_VERSION_CORE", "YAMS_API_VERSION_CORE", default="dev")
    API_VERSION_PLUGINS = chain_load_setting("API_VERSION_PLUGINS", "YAMS_API_VERSION_PLUGINS", default="dev")

    default_datadir = os.path.join(basedir, "yams_api", "data")
    DATADIR = chain_load_setting("API_DATADIR", "YAMS_API_DATADIR", default=default_datadir)

    default_database = "sqlite:///" + os.path.join(basedir, "yams.sqlite")
    SQLALCHEMY_DATABASE_URI = chain_load_setting("APP_DATABASE_URI", "YAMS_APP_DATABASE_URI", default=default_database)

    SITE_NAME = chain_load_setting("APP_REBRANDING_NAME", "YAMS_REBRANDING_NAME", default="YAMS")


class API:

    LISTEN_HOST = chain_load_setting("API_HOST", "YAMS_API_HOST", "127.0.0.1")
    LISTEN_PORT = chain_load_setting("API_PORT", "YAMS_API_PORT", default=1111)
    LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)
    # ----------------------------------------- #
    # ---- Socket API ---- #

# Path: config_loader.py
# def chain_load_setting(config_file_option, envvar, default):
#     # Settings file order (last wins)
#     # 1. Default
#     # 2. Settings file
#     # 3. Env var
# 
#     # 1
#     value = default
# 
#     # 2
#     _conf_value = get_option_config_file(config_file_option)
#     if _conf_value is not None:  # valid _conf_value could be Falsey
#         value = _conf_value
# 
#     # 3
#     value = os.getenv(envvar, value)
# 
#     return value


# Path: config.py
import os
import random
import redis
import string
import tempfile
from easyos import easyos
from config_loader import chain_load_setting
    from version import version
from config_plugins import *



class APP:

    LISTEN_HOST = chain_load_setting("APP_HOST", "YAMS_APP_HOST", "127.0.0.1")
    LISTEN_PORT = chain_load_setting("APP_PORT", "YAMS_APP_PORT", default=1110)
    LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)

    DEBUG = chain_load_setting("DEBUG", "YAMS_DEBUG", True)
    DEBUG_FRONTEND = chain_load_setting("DEBUG_FRONTEND", "YAMS_DEBUG_FRONTEND", False)

    API_VERSION_CORE = chain_load_setting("API_VERSION_CORE", "YAMS_API_VERSION_CORE", default="dev")
    API_VERSION_PLUGINS = chain_load_setting("API_VERSION_PLUGINS", "YAMS_API_VERSION_PLUGINS", default="dev")

    default_datadir = os.path.join(basedir, "yams_api", "data")
    DATADIR = chain_load_setting("API_DATADIR", "YAMS_API_DATADIR", default=default_datadir)

    default_database = "sqlite:///" + os.path.join(basedir, "yams.sqlite")
    SQLALCHEMY_DATABASE_URI = chain_load_setting("APP_DATABASE_URI", "YAMS_APP_DATABASE_URI", default=default_database)

    SITE_NAME = chain_load_setting("APP_REBRANDING_NAME", "YAMS_REBRANDING_NAME", default="YAMS")


class API:

    LISTEN_HOST = chain_load_setting("API_HOST", "YAMS_API_HOST", "127.0.0.1")
    LISTEN_PORT = chain_load_setting("API_PORT", "YAMS_API_PORT", default=1111)
    LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)
    # ----------------------------------------- #
    # ---- Socket API ---- #

    LISTEN_PORT_SOCKET = chain_load_setting("API_SOCKET_PORT", "YAMS_API_SOCKET_PORT", default=1112)