from pyramid.config import Configurator

from sqlalchemy import engine_from_config

from .models import DBSession, Base

def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    config = Configurator(settings=settings,
                          root_factory='poconsole.models.Root')
    config.include('pyramid_chameleon')

    # Configs
    config.add_route('configs', '/api/configs')
    config.add_route('config', '/api/configs/{_id}')

    # Configs
    config.add_route('configs', '/api/configs')
    config.add_route('config', '/api/configs/{_id}')

    # Device Types
    config.add_route('device_types', '/api/device_types')
    config.add_route('device_type', '/api/device_types/{_id}')


    config.add_route('wiki_view', '/')
    config.add_route('wikipage_add', '/add')
    config.add_route('wikipage_view', '/{uid}')
    config.add_route('wikipage_edit', '/{uid}/edit')
    config.add_static_view('deform_static', 'deform:static/')
    config.scan('.views')
    return config.make_wsgi_app()