# Path: swf/models/event/base.py
# class Event(object):
#     """Simple workflow execution event wrapper base class
# 
#     Intends to be used as a base abstraction for the multiple amazon
#     swf events implementation. Generally events implementation
#     will be instantiated through the ``swf.models.event.factory.EventFactory``
#     factory.
# 
#     It provides basic common attributes, such as the event type,
#     name, json representation key to extract relevant data from,
#     and sets the event id, state and timestamp from the constructor.
# 
#     Event base class is used in this project to implement
#     ``swf.models.event.task.DecisionTaskEvent``, which a typical
#     instance would for example have type 'DecisionTask',
#     name 'DecisionTaskScheduleFailed', id '1' and state 'failed'.
# 
#     :param  id: event id provided by amazon service
#     :type   id: string
# 
#     :param  state: event current state
#     :type   state: string
# 
#     :param  timestamp: event creation timestamp
#     :type   timestamp: float
# 
#     :param  raw_data: raw_event representation provided by amazon service
#     :type   raw_data: dict
#     """
#     _type = None
#     _name = None
#     _attributes_key = None
#     _attributes = None
# 
#     excluded_attributes = (
#         'eventId',
#         'eventType',
#         'eventTimestamp'
#     )
# 
#     def __init__(self, id, state, timestamp, raw_data):
#         """
#         """
#         self._id = id
#         self._state = state
#         self._timestamp = timestamp
#         self._input = {}
#         self.raw = raw_data or {}
# 
#         self.process_attributes()
# 
#     def __repr__(self):
#         return '<Event %s %s : %s >' % (self.id, self.type, self.state)
# 
#     @property
#     def id(self):
#         return self._id
# 
#     @property
#     def type(self):
#         return self._type
# 
#     @property
#     def name(self):
#         return self._name
# 
#     @property
#     def state(self):
#         return self._state
# 
#     @cached_property
#     def timestamp(self):
#         return datetime.fromtimestamp(self._timestamp)
# 
#     @property
#     def input(self):
#         return self._input
# 
#     @input.setter
#     def input(self, value):
#         self._input = json.loads(value)
# 
#     def process_attributes(self):
#         """Processes the event raw_data attributes_key elements
#         and sets current instance attributes accordingly"""
#         for key, value in self.raw[self._attributes_key].iteritems():
#             setattr(self, camel_to_underscore(key), value)
# 
# Path: swf/models/event/compiler.py
# class CompiledEvent(Event, Stateful):
#     """State-aware history event base representation
# 
#     Amazon service history events comes with a type and
#     a state. swf.models.eventEvent class already implements
#     these specifities.
# 
#     But history manipulation and analysis in order to take
#     decisions calls for state-aware events.
# 
#     CompiledEvent has to be instantiated against an swf.models.event.Event
#     from which it will validate state as initial. Then, you will be able
#     to apply transitions to it from events of the same type that comes next
#     in the history using the .transit() method, which will
#     validate the state transition is attended and valid.
# 
#     compiled events inherits from swf.models.compiled.event.Stateful and should
#     should implement
# 
#     * ``initial_state`` class attribute: constructor supplied event attended state
#     * ``states`` (tuple) class attribute: every event type possible states should
#     be listed
#     * ``transitions`` (dictionary) class attribute: every initial state to possible
#     target state should be listed.
# 
#     Implementation **example** can be found in swf.models.event submodules as Compiled*Event
#     classes.
# 
#     """
# 
#     initial_state = None
# 
#     def __init__(self, event):
#         """Builds a  CompiledEvent from provided ``event``
# 
#         validates provided history event is in compiled event
#         attended initial_state.
# 
#         :param  event: base event to build the compiled event upon
#         :type   event: swf.models.event.Event
#         """
#         if event.state != self.initial_state:
#             raise InconsistentStateError("Provided event is in {0} state "
#                                          "when attended intial state is {1}"
#                                          .format(event.state, self.initial_state))
#         self.__dict__ = event.__dict__.copy()
# 
#     def __repr__(self):
#         return '<CompiledEvent %s %s>' % (self.type, self.state)
# 
#     @property
#     def next_states(self):
#         """Returns attended next compiled event states
# 
#         :rtype: list
#         """
#         return self.transitions[self.state]
# 
#     def transit(self, event):
#         """Tries to apply CompiledEvent transition to the provided ``event``
#         state
# 
#         :param  event: event to use in order to apply the compiled event
#                        state transition
#         :type   event: swf.models.event.Event
#         """
#         if event.state not in self.transitions[self.state]:
#             raise TransitionError("Transition to state %s not allowed")
# 
#         self.__dict__ = event.__dict__.copy()


from swf.models.event.base import Event
from swf.models.event.compiler import CompiledEvent
    initial_state = 'started'


class ChildWorkflowExecutionEvent(Event):
    _type = 'ChildWorkflowExecution'


class CompiledChildWorkflowExecutionEvent(CompiledEvent):
    _type = 'ChildWorkflowExecution'

    states = (
        'start_initiated',  # A request was made to start a child workflow execution
        'start_failed',  # Failed to process start decision
        'started',  # successfully started
        'completed',  # started by this workflow execution, completed successfully and was closed
        'failed',  # started by this workflow execution, failed to complete successfully and was closed
        'timed_out',  # started by this workflow execution, timed out and was closed
        'canceled',  # started by this workflow execution, was canceled and closed
        'terminated',  # started by this workflow execution, was terminated
    )

    transitions = {
        'start_initiated': ('start_failed', 'started'),
        'start_failed': ('failed'),
        'started': ('canceled', 'failed', 'timed_out', 'terminated'),
    }

    initial_state = 'start_initiated'



# Path: swf/models/event/base.py
# class Event(object):
#     """Simple workflow execution event wrapper base class
# 
#     Intends to be used as a base abstraction for the multiple amazon
#     swf events implementation. Generally events implementation
#     will be instantiated through the ``swf.models.event.factory.EventFactory``
#     factory.
# 
#     It provides basic common attributes, such as the event type,
#     name, json representation key to extract relevant data from,
#     and sets the event id, state and timestamp from the constructor.
# 
#     Event base class is used in this project to implement
#     ``swf.models.event.task.DecisionTaskEvent``, which a typical
#     instance would for example have type 'DecisionTask',
#     name 'DecisionTaskScheduleFailed', id '1' and state 'failed'.
# 
#     :param  id: event id provided by amazon service
#     :type   id: string
# 
#     :param  state: event current state
#     :type   state: string
# 
#     :param  timestamp: event creation timestamp
#     :type   timestamp: float
# 
#     :param  raw_data: raw_event representation provided by amazon service
#     :type   raw_data: dict
#     """
#     _type = None
#     _name = None
#     _attributes_key = None
#     _attributes = None
# 
#     excluded_attributes = (
#         'eventId',
#         'eventType',
#         'eventTimestamp'
#     )
# 
#     def __init__(self, id, state, timestamp, raw_data):
#         """
#         """
#         self._id = id
#         self._state = state
#         self._timestamp = timestamp
#         self._input = {}
#         self.raw = raw_data or {}
# 
#         self.process_attributes()
# 
#     def __repr__(self):
#         return '<Event %s %s : %s >' % (self.id, self.type, self.state)
# 
#     @property
#     def id(self):
#         return self._id
# 
#     @property
#     def type(self):
#         return self._type
# 
#     @property
#     def name(self):
#         return self._name
# 
#     @property
#     def state(self):
#         return self._state
# 
#     @cached_property
#     def timestamp(self):
#         return datetime.fromtimestamp(self._timestamp)
# 
#     @property
#     def input(self):
#         return self._input
# 
#     @input.setter
#     def input(self, value):
#         self._input = json.loads(value)
# 
#     def process_attributes(self):
#         """Processes the event raw_data attributes_key elements
#         and sets current instance attributes accordingly"""
#         for key, value in self.raw[self._attributes_key].iteritems():
#             setattr(self, camel_to_underscore(key), value)
# 
# Path: swf/models/event/compiler.py
# class CompiledEvent(Event, Stateful):
#     """State-aware history event base representation
# 
#     Amazon service history events comes with a type and
#     a state. swf.models.eventEvent class already implements
#     these specifities.
# 
#     But history manipulation and analysis in order to take
#     decisions calls for state-aware events.
# 
#     CompiledEvent has to be instantiated against an swf.models.event.Event
#     from which it will validate state as initial. Then, you will be able
#     to apply transitions to it from events of the same type that comes next
#     in the history using the .transit() method, which will
#     validate the state transition is attended and valid.
# 
#     compiled events inherits from swf.models.compiled.event.Stateful and should
#     should implement
# 
#     * ``initial_state`` class attribute: constructor supplied event attended state
#     * ``states`` (tuple) class attribute: every event type possible states should
#     be listed
#     * ``transitions`` (dictionary) class attribute: every initial state to possible
#     target state should be listed.
# 
#     Implementation **example** can be found in swf.models.event submodules as Compiled*Event
#     classes.
# 
#     """
# 
#     initial_state = None
# 
#     def __init__(self, event):
#         """Builds a  CompiledEvent from provided ``event``
# 
#         validates provided history event is in compiled event
#         attended initial_state.
# 
#         :param  event: base event to build the compiled event upon
#         :type   event: swf.models.event.Event
#         """
#         if event.state != self.initial_state:
#             raise InconsistentStateError("Provided event is in {0} state "
#                                          "when attended intial state is {1}"
#                                          .format(event.state, self.initial_state))
#         self.__dict__ = event.__dict__.copy()
# 
#     def __repr__(self):
#         return '<CompiledEvent %s %s>' % (self.type, self.state)
# 
#     @property
#     def next_states(self):
#         """Returns attended next compiled event states
# 
#         :rtype: list
#         """
#         return self.transitions[self.state]
# 
#     def transit(self, event):
#         """Tries to apply CompiledEvent transition to the provided ``event``
#         state
# 
#         :param  event: event to use in order to apply the compiled event
#                        state transition
#         :type   event: swf.models.event.Event
#         """
#         if event.state not in self.transitions[self.state]:
#             raise TransitionError("Transition to state %s not allowed")
# 
#         self.__dict__ = event.__dict__.copy()


# Path: swf/models/event/workflow.py
from swf.models.event.base import Event
from swf.models.event.compiler import CompiledEvent

    initial_state = 'started'


class ChildWorkflowExecutionEvent(Event):
    _type = 'ChildWorkflowExecution'


class CompiledChildWorkflowExecutionEvent(CompiledEvent):
    _type = 'ChildWorkflowExecution'

    states = (
        'start_initiated',  # A request was made to start a child workflow execution
        'start_failed',  # Failed to process start decision
        'started',  # successfully started
        'completed',  # started by this workflow execution, completed successfully and was closed
        'failed',  # started by this workflow execution, failed to complete successfully and was closed
        'timed_out',  # started by this workflow execution, timed out and was closed
        'canceled',  # started by this workflow execution, was canceled and closed
        'terminated',  # started by this workflow execution, was terminated
    )

    transitions = {
        'start_initiated': ('start_failed', 'started'),
        'start_failed': ('failed'),
        'started': ('canceled', 'failed', 'timed_out', 'terminated'),
    }

    initial_state = 'start_initiated'



class ExternalWorkflowExecutionEvent(Event):