# Path: djangoevents/domain.py
# class BaseAggregate(EventSourcedEntity):
# class BaseEntity(BaseAggregate):
#     def is_abstract_class(cls):
#     def mutate(cls, aggregate=None, event=None):
#     def create_for_event(cls, event):
#     def is_abstract_class(cls):
#     def mutate(cls, entity=None, event=None):
# 
# Path: djangoevents/exceptions.py
# class EventSchemaError(DjangoeventsError):
#     pass
# 
# Path: djangoevents/settings.py
# def adds_schema_version_to_event_data():
#     config = get_config()
#     return config.get('ADDS_SCHEMA_VERSION_TO_EVENT_DATA', False)
# 
# Path: djangoevents/schema.py
# def get_event_version(event_cls):
#     return getattr(event_cls, 'version', None) or 1
# 
# Path: djangoevents/schema.py
# def load_all_event_schemas():
#     """
#     Initializes aggregate event schemas lookup cache.
#     """
#     errors = []
#     for aggregate in list_concrete_aggregates():
#         for event in list_aggregate_events(aggregate_cls=aggregate):
#             try:
#                 schemas[event] = load_event_schema(aggregate, event)
#             except EventSchemaError as e:
#                 errors.append(str(e))
# 
#     # Serve all schema errors at once not iteratively.
#     if errors:
#         raise EventSchemaError("\n".join(errors))
# 
#     return schemas


from django.apps import AppConfig as BaseAppConfig
from django.conf import settings
from django.utils.module_loading import autodiscover_modules
from djangoevents import DomainEvent
from .exceptions import EventSchemaError
from .settings import adds_schema_version_to_event_data
from .schema import get_event_version
from .schema import load_all_event_schemas
import warnings
def get_app_module_names():
    return settings.INSTALLED_APPS


def load_schemas():
    """
    Try loading all the event schemas and complain loud if failure occurred.
    """
    try:
        load_all_event_schemas()
    except EventSchemaError as e:
        warnings.warn(str(e), UserWarning)


def patch_domain_event():
    """
    Patch `DomainEvent` to add `schema_version` to event payload.
    """

    old_init = DomainEvent.__init__

    def new_init(self, *args, **kwargs):
        old_init(self, *args, **kwargs)

        if adds_schema_version_to_event_data():
            dct = self.__dict__
            key = 'schema_version'
            if key not in dct:
                dct[key] = get_event_version(self.__class__)


# Path: djangoevents/domain.py
# class BaseAggregate(EventSourcedEntity):
# class BaseEntity(BaseAggregate):
#     def is_abstract_class(cls):
#     def mutate(cls, aggregate=None, event=None):
#     def create_for_event(cls, event):
#     def is_abstract_class(cls):
#     def mutate(cls, entity=None, event=None):
# 
# Path: djangoevents/exceptions.py
# class EventSchemaError(DjangoeventsError):
#     pass
# 
# Path: djangoevents/settings.py
# def adds_schema_version_to_event_data():
#     config = get_config()
#     return config.get('ADDS_SCHEMA_VERSION_TO_EVENT_DATA', False)
# 
# Path: djangoevents/schema.py
# def get_event_version(event_cls):
#     return getattr(event_cls, 'version', None) or 1
# 
# Path: djangoevents/schema.py
# def load_all_event_schemas():
#     """
#     Initializes aggregate event schemas lookup cache.
#     """
#     errors = []
#     for aggregate in list_concrete_aggregates():
#         for event in list_aggregate_events(aggregate_cls=aggregate):
#             try:
#                 schemas[event] = load_event_schema(aggregate, event)
#             except EventSchemaError as e:
#                 errors.append(str(e))
# 
#     # Serve all schema errors at once not iteratively.
#     if errors:
#         raise EventSchemaError("\n".join(errors))
# 
#     return schemas


# Path: djangoevents/apps.py
from django.apps import AppConfig as BaseAppConfig
from django.conf import settings
from django.utils.module_loading import autodiscover_modules
from djangoevents import DomainEvent
from .exceptions import EventSchemaError
from .settings import adds_schema_version_to_event_data
from .schema import get_event_version
from .schema import load_all_event_schemas
import warnings

def get_app_module_names():
    return settings.INSTALLED_APPS


def load_schemas():
    """
    Try loading all the event schemas and complain loud if failure occurred.
    """
    try:
        load_all_event_schemas()
    except EventSchemaError as e:
        warnings.warn(str(e), UserWarning)


def patch_domain_event():
    """
    Patch `DomainEvent` to add `schema_version` to event payload.
    """

    old_init = DomainEvent.__init__

    def new_init(self, *args, **kwargs):
        old_init(self, *args, **kwargs)

        if adds_schema_version_to_event_data():
            dct = self.__dict__
            key = 'schema_version'
            if key not in dct:
                dct[key] = get_event_version(self.__class__)


    DomainEvent.__init__ = new_init