# Path: djangoevents/settings.py
# def get_avro_dir():
#     config = get_config()
# 
#     try:
#         avro_folder = config.get('EVENT_SCHEMA_VALIDATION', {})['SCHEMA_DIR']
#     except KeyError:
#         raise ImproperlyConfigured("Please define `SCHEMA_DIR`")
# 
#     avro_dir = os.path.abspath(os.path.join(settings.BASE_DIR, '..', avro_folder))
#     return avro_dir
# 
# Path: djangoevents/utils.py
# def list_concrete_aggregates():
#     """
#     Lists all non abstract aggregates defined within the application.
#     """
#     aggregates = set(_list_subclasses(BaseAggregate) + _list_subclasses(BaseEntity))
#     return [aggregate for aggregate in aggregates if not aggregate.is_abstract_class()]
# 
# Path: djangoevents/utils.py
# def list_aggregate_events(aggregate_cls):
#     """
#     Lists all aggregate_cls events defined within the application.
#     Note: Only events with a defined `mutate_event` flow and are not marked as abstract will be returned.
#     """
#     events = _list_internal_classes(aggregate_cls, DomainEvent)
#     return [event_cls for event_cls in events if is_event_mutating(event_cls) and not is_abstract(event_cls)]
# 
# Path: djangoevents/utils.py
# def event_to_json(event):
#     """
#     Converts an event class to its dictionary representation.
#     Underlying eventsourcing library does not provide a proper event->dict conversion function.
# 
#     Note: Similarly to event journal persistence flow, this method supports native JSON types only.
#     """
#     return vars(event)
# 
# Path: djangoevents/exceptions.py
# class EventSchemaError(DjangoeventsError):
#     pass


import avro.schema
import itertools
import os
import stringcase
from avro.io import Validate as avro_validate
from .settings import get_avro_dir
from .utils import list_concrete_aggregates
from .utils import list_aggregate_events
from .utils import event_to_json
from .exceptions import EventSchemaError
        else:
            break

    return version


def _event_to_schema_path(aggregate_cls, event_cls, avro_dir, version):
    aggregate_name = decode_cls_name(aggregate_cls)
    event_name = decode_cls_name(event_cls)

    filename = "v{version}_{aggregate_name}_{event_name}.json".format(
        aggregate_name=aggregate_name, event_name=event_name, version=version)

    return os.path.join(avro_dir, aggregate_name, filename)


def decode_cls_name(cls):
    """
    Convert camel case class name to snake case names used in event documentation.
    """
    return stringcase.snakecase(cls.__name__)


def parse_event_schema(spec_body):
    schema = avro.schema.Parse(spec_body)
    return schema


def get_schema_for_event(event_cls):
    if event_cls not in schemas:

# Path: djangoevents/settings.py
# def get_avro_dir():
#     config = get_config()
# 
#     try:
#         avro_folder = config.get('EVENT_SCHEMA_VALIDATION', {})['SCHEMA_DIR']
#     except KeyError:
#         raise ImproperlyConfigured("Please define `SCHEMA_DIR`")
# 
#     avro_dir = os.path.abspath(os.path.join(settings.BASE_DIR, '..', avro_folder))
#     return avro_dir
# 
# Path: djangoevents/utils.py
# def list_concrete_aggregates():
#     """
#     Lists all non abstract aggregates defined within the application.
#     """
#     aggregates = set(_list_subclasses(BaseAggregate) + _list_subclasses(BaseEntity))
#     return [aggregate for aggregate in aggregates if not aggregate.is_abstract_class()]
# 
# Path: djangoevents/utils.py
# def list_aggregate_events(aggregate_cls):
#     """
#     Lists all aggregate_cls events defined within the application.
#     Note: Only events with a defined `mutate_event` flow and are not marked as abstract will be returned.
#     """
#     events = _list_internal_classes(aggregate_cls, DomainEvent)
#     return [event_cls for event_cls in events if is_event_mutating(event_cls) and not is_abstract(event_cls)]
# 
# Path: djangoevents/utils.py
# def event_to_json(event):
#     """
#     Converts an event class to its dictionary representation.
#     Underlying eventsourcing library does not provide a proper event->dict conversion function.
# 
#     Note: Similarly to event journal persistence flow, this method supports native JSON types only.
#     """
#     return vars(event)
# 
# Path: djangoevents/exceptions.py
# class EventSchemaError(DjangoeventsError):
#     pass


# Path: djangoevents/schema.py
import avro.schema
import itertools
import os
import stringcase
from avro.io import Validate as avro_validate
from .settings import get_avro_dir
from .utils import list_concrete_aggregates
from .utils import list_aggregate_events
from .utils import event_to_json
from .exceptions import EventSchemaError

        else:
            break

    return version


def _event_to_schema_path(aggregate_cls, event_cls, avro_dir, version):
    aggregate_name = decode_cls_name(aggregate_cls)
    event_name = decode_cls_name(event_cls)

    filename = "v{version}_{aggregate_name}_{event_name}.json".format(
        aggregate_name=aggregate_name, event_name=event_name, version=version)

    return os.path.join(avro_dir, aggregate_name, filename)


def decode_cls_name(cls):
    """
    Convert camel case class name to snake case names used in event documentation.
    """
    return stringcase.snakecase(cls.__name__)


def parse_event_schema(spec_body):
    schema = avro.schema.Parse(spec_body)
    return schema


def get_schema_for_event(event_cls):
    if event_cls not in schemas:

        raise EventSchemaError("Cached Schema not found for: {}".format(event_cls))