"""
Configuration for Rookeries app

:copyright: Copyright 2013-2017, Dorian Puła <dorian.pula@amber-penguin-software.ca>
:license: AGPL v3+
"""

import uuid

from flask_appconfig import env

from rookeries import database, security

ROOKERIES_ENV_CONFIG_PREFIX = 'ROOKERIES_'


class DefaultConfig(object):
    """Default configuration for Rookeries."""
    DEBUG = True
    COUCHDB = database.DEFAULT_DB_CONNECTION

    # Security config
    # Key used by Flask for session secrets.
    SECRET_KEY = str(uuid.uuid4())

    # Key required by Flask-JWT.  Please change this default!
    JWT_SECRET_KEY = security.DEFAULT_JWT_SECRET_KEY


def configure_app(web_app):
    """
    Configure the app first by its default than by a known filename and than
    an environment variable.
    """
    web_app.config.from_object(DefaultConfig)
    env.from_envvars(conf=web_app.config, prefix=ROOKERIES_ENV_CONFIG_PREFIX, as_json=False)
    return web_app
