# Path: suma/common/services/factories.py
# def link_service_factory(context, request):
#     dbsession = request.find_service(name='db', context=context)
#     hashid = request.find_service(name='hashid', context=context)
#     return LinkService(
#         dbsession=dbsession,
#         hashid=hashid,
#     )
# 
# def task_service_factory(context, request):
#     return TaskService()
# 
# def file_service_factory(context, request):
#     if asbool(request.registry.settings.get('storage.s3', False)):
#         return S3FileService(
#             request.registry.settings['storage.s3.base_url'],
#             request.registry.settings['storage.s3.bucket_name'],
#             request.registry.settings['storage.s3.access_key'],
#             request.registry.settings['storage.s3.secret_key'],
#         )
#     return LocalFileService(
#         request.registry.settings['storage.local.base_url'],
#         request.registry.settings['storage.local.base_path'],
#     )
# 
# def hashid_service_factory(context, request):
#     hashid_secret = request.registry.settings.get('hashid.secret')
#     return HashIdService(
#         secret=hashid_secret
#     )
# 
# Path: suma/core/models/meta/base.py
# def create_dbsession(engine):
#     dbsession = scoped_session(sessionmaker())
#     dbsession.configure(bind=engine)
#     Base.metadata.bind = engine
#     return dbsession


from suma.common.services import (
    link_service_factory,
    task_service_factory,
    hashid_service_factory,
    file_service_factory
)
from sqlalchemy import engine_from_config
from suma.core.models.meta import (
    create_dbsession
)
import zope.sqlalchemy


def includeme(config):
    engine = engine_from_config(config.registry.settings, 'sqlalchemy.')
    dbsession = create_dbsession(engine)
    zope.sqlalchemy.register(dbsession, keep_session=True)

    config.register_service(
        dbsession,
        name='db'
    )

    config.register_service_factory(
        link_service_factory,
        name='link'
    )

    # Needed just to initialize the link_service
    config.register_service_factory(
        hashid_service_factory,
        name='hashid'
    )

    config.register_service_factory(
        task_service_factory,
        name='task'
    )

    config.register_service_factory(
        file_service_factory,

# Path: suma/common/services/factories.py
# def link_service_factory(context, request):
#     dbsession = request.find_service(name='db', context=context)
#     hashid = request.find_service(name='hashid', context=context)
#     return LinkService(
#         dbsession=dbsession,
#         hashid=hashid,
#     )
# 
# def task_service_factory(context, request):
#     return TaskService()
# 
# def file_service_factory(context, request):
#     if asbool(request.registry.settings.get('storage.s3', False)):
#         return S3FileService(
#             request.registry.settings['storage.s3.base_url'],
#             request.registry.settings['storage.s3.bucket_name'],
#             request.registry.settings['storage.s3.access_key'],
#             request.registry.settings['storage.s3.secret_key'],
#         )
#     return LocalFileService(
#         request.registry.settings['storage.local.base_url'],
#         request.registry.settings['storage.local.base_path'],
#     )
# 
# def hashid_service_factory(context, request):
#     hashid_secret = request.registry.settings.get('hashid.secret')
#     return HashIdService(
#         secret=hashid_secret
#     )
# 
# Path: suma/core/models/meta/base.py
# def create_dbsession(engine):
#     dbsession = scoped_session(sessionmaker())
#     dbsession.configure(bind=engine)
#     Base.metadata.bind = engine
#     return dbsession


# Path: suma/web/settings/service.py
from suma.common.services import (
    link_service_factory,
    task_service_factory,
    hashid_service_factory,
    file_service_factory
)
from sqlalchemy import engine_from_config
from suma.core.models.meta import (
    create_dbsession
)
import zope.sqlalchemy



def includeme(config):
    engine = engine_from_config(config.registry.settings, 'sqlalchemy.')
    dbsession = create_dbsession(engine)
    zope.sqlalchemy.register(dbsession, keep_session=True)

    config.register_service(
        dbsession,
        name='db'
    )

    config.register_service_factory(
        link_service_factory,
        name='link'
    )

    # Needed just to initialize the link_service
    config.register_service_factory(
        hashid_service_factory,
        name='hashid'
    )

    config.register_service_factory(
        task_service_factory,
        name='task'
    )

    config.register_service_factory(
        file_service_factory,

        name='file'