# -*- coding: utf-8 -*-
from flask import Flask
from flask.ext.moment import Moment
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager


moment = Moment()
db = SQLAlchemy()
login_manager = LoginManager()
login_manager.session_protection = u'strong'
login_manager.login_view = u'auth.login'


def create_app(config_name):
    from config import config
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

    if not app.debug and not app.testing and not app.config[u'SSL_DISABLE']:
        from flask.ext.sslify import SSLify
        sslify = SSLify(app)

    from .main import main_blueprint, auth_blueprint, \
        blog_blueprint, music_blueprint, movie_blueprint, photo_blueprint, files_blueprint
    app.register_blueprint(main_blueprint)
    app.register_blueprint(auth_blueprint)
    app.register_blueprint(blog_blueprint)
    app.register_blueprint(photo_blueprint)
    app.register_blueprint(files_blueprint)
    app.register_blueprint(movie_blueprint)
    app.register_blueprint(music_blueprint)

    # from .api_1_0 import api as api_1_0_blueprint
    # app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0')

    return app
