"""
Configuration for Rookeries app

:copyright: Copyright 2013-2016, Dorian Pula <dorian.pula@amber-penguin-software.ca>
:license: AGPL v3+
"""

import uuid

from flask_appconfig import env

ROOKERIES_ENV_CONFIG_PREFIX = 'ROOKERIES_'


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

    # Database connection string.
    SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://admin:password@localhost:5432/rookeries'

    # Admin user credentials as Rookeries is a single user app.
    # TODO: Remove this and create an initialization script.
    ADMIN_USERNAME = 'admin'
    ADMIN_PASSWORD = 'password'

    # 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 = 'problematic_penguins'


def configure_web_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)
