from flow.protocol.message import Message

class UpdateMessage(Message):
    required_fields = {
            'workflow_plan_id': int,

            'net_key': basestring,
            'operation_id': int,
            'color': int,

            'name': basestring,

            'status': basestring,
     }

    optional_fields = {
            'parent_net_key': basestring,
            'parent_operation_id': int,
            'parent_color': int,

            'peer_net_key': basestring,
            'peer_operation_id': int,
            'peer_color': int,

            'parallel_index': int,

            'dispatch_id': basestring,

            'user_name': basestring,

            'start_time': basestring,
            'end_time': basestring,

            'stdout': basestring,
            'stderr': basestring,

            'exit_code': int,
    }

# XXX use validate or data clumps for net_key/operation_id/color combinations.

from flow.protocol.message import Message
from flow_workflow.historian.storage import STATUSES

class UpdateMessage(Message):
    required_fields = {
            'workflow_plan_id': int,

            'net_key': basestring,
            'operation_id': int,
            'color': int,

            'name': basestring,

            'status': basestring,
     }

    optional_fields = {
            'parent_net_key': basestring,
            'parent_operation_id': int,
            'parent_color': int,

            'peer_net_key': basestring,
            'peer_operation_id': int,
            'peer_color': int,

            'parallel_index': int,

            'dispatch_id': basestring,

            'user_name': basestring,

            'start_time': basestring,
            'end_time': basestring,

            'stdout': basestring,
            'stderr': basestring,

            'exit_code': int,
    }

    def validate(self):
        Message.validate(self)
        if self.status not in STATUSES:
            raise ValueError('UpdateMessage.status field must be one of %s, not %s' %
                    STATUSES, self.status)
# XXX use data clumps for net_key/operation_id/color combinations.

validate statuses in the historian message