"""
NavConfig.

Main object for Configuration of several Navigator-related Tools.
"""
import sys
import os
from pathlib import Path
from .version import (
    __title__, __description__, __version__, __author__, __author_email__
)
from .config import navigatorConfig # noqa

def is_virtualenv():
    return (
        hasattr(sys, 'real_prefix') or (
            hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
    )


# PROJECT PATH IS DEFINED?
SITE_ROOT = os.getenv('SITE_ROOT', None)

if not SITE_ROOT:
    # get Project PATH
    if is_virtualenv():
        SITE_ROOT = Path(sys.prefix).resolve().parent
    else:
        SITE_ROOT = Path(os.path.abspath(
            os.path.dirname(__file__))).resolve().parent.parent
    if not SITE_ROOT:
        SITE_ROOT = Path(sys.prefix).resolve().parent
else:
    SITE_ROOT = Path(SITE_ROOT).resolve()


BASE_DIR = os.getenv('BASE_DIR', None)
if not BASE_DIR:
    BASE_DIR = SITE_ROOT
else:
    BASE_DIR = Path(BASE_DIR).resolve()

SETTINGS_DIR = BASE_DIR.joinpath('settings')

# configuration of the environment type:
ENV_TYPE = os.getenv('ENV_TYPE', 'file')

"""
Loading main Configuration Object.
"""
config = navigatorConfig(SITE_ROOT, env_type = ENV_TYPE)
ENV = config.ENV

# DEBUG VERSION
DEBUG = config.debug

# SECURITY WARNING: keep the secret keys used in production secret!
PRODUCTION = config.getboolean('PRODUCTION', fallback=bool(not DEBUG))

# Add Path Navigator to Sys path
sys.path.append(str(BASE_DIR))
sys.path.append(str(SETTINGS_DIR))
