# Path: services/mgmt.py
# def get_available_services(component=None, exclude=None, include=None):
#     """
#     Get all available services which implement a particular component (or all services if
#     'component' is None). Allows excluding particular services and restricting those from which to filter.
#     :param component: component (mixin) that should be implemented by returned services
#     :param exclude: exclude services passed through this parameter (should be a list of service names)
#     :param include: consider only services passed through this parameter (should be a list of service names)
#     :return: list of matching services (can be empty)
#     """
#     out_services = list()
#     for service in available_services:
#         if component is not None:
#             if component not in service.implemented_components:
#                 continue
#         if exclude is not None:
#             if service.name in exclude:
#                 continue
#         if include is not None:
#             if service.name not in include:
#                 continue
#         out_services.append(service)
#     return out_services
# 
# def get_service_by_id(service_id):
#     for service in available_services:
#         if service.id == service_id:
#             return service
#     raise ACServiceDoesNotExist('Service with id {0} does not exist'.format(service_id))
# 
# Path: api/response_aggregator.py
# def get_response_aggregator():
#     return response_aggregator


from django.conf import settings
from ac_mediator.exceptions import *
from services.acservice.constants import *
from services.mgmt import get_available_services, get_service_by_id
from api.response_aggregator import get_response_aggregator
from celery import shared_task

response_aggregator = get_response_aggregator()


@shared_task
def perform_request_and_aggregate(request, response_id, service_id):

# Path: services/mgmt.py
# def get_available_services(component=None, exclude=None, include=None):
#     """
#     Get all available services which implement a particular component (or all services if
#     'component' is None). Allows excluding particular services and restricting those from which to filter.
#     :param component: component (mixin) that should be implemented by returned services
#     :param exclude: exclude services passed through this parameter (should be a list of service names)
#     :param include: consider only services passed through this parameter (should be a list of service names)
#     :return: list of matching services (can be empty)
#     """
#     out_services = list()
#     for service in available_services:
#         if component is not None:
#             if component not in service.implemented_components:
#                 continue
#         if exclude is not None:
#             if service.name in exclude:
#                 continue
#         if include is not None:
#             if service.name not in include:
#                 continue
#         out_services.append(service)
#     return out_services
# 
# def get_service_by_id(service_id):
#     for service in available_services:
#         if service.id == service_id:
#             return service
#     raise ACServiceDoesNotExist('Service with id {0} does not exist'.format(service_id))
# 
# Path: api/response_aggregator.py
# def get_response_aggregator():
#     return response_aggregator


# Path: api/request_distributor.py
from django.conf import settings
from ac_mediator.exceptions import *
from services.acservice.constants import *
from services.mgmt import get_available_services, get_service_by_id
from api.response_aggregator import get_response_aggregator
from celery import shared_task


response_aggregator = get_response_aggregator()


@shared_task
def perform_request_and_aggregate(request, response_id, service_id):

    service = get_service_by_id(service_id)