import "org/drools/core/marshalling/droolsmessages.proto";

package org.jbpm.marshalling;

option java_package = "org.jbpm.marshalling.impl";
option java_outer_classname = "JBPMMessages";


// WARNING: Before changing this file, make sure you know what you
// are doing by reading the protobuf documentation at
//
// http://code.google.com/apis/protocolbuffers/
//
// in special, please node that to keep backward compatibility
// you need to comply to a set of practices that are listed on the
// documentation and quoted here:
//
// * you must not change the tag numbers of any existing fields.
// * you must not add or delete any required fields. At this moment,
//   as a best practice we are not using required fields at all.
// * you may delete optional or repeated fields. The best practice
//   though is to rename the field by prepending it with the prefix
//   OBSOLETE_
// * you may add new optional or repeated fields but you must use
//   fresh tag numbers (i.e. tag numbers that were never used in
//   this protocol buffer, not even by deleted fields).

extend org.drools.core.marshalling.ProcessData {
    repeated ProcessInstance process_instance = 10;
    repeated WorkItem work_item = 11;
    optional int64 timer_id = 13;
    repeated ProcessTimer process_timer = 12;
}

message ProcessInstance {
    optional string process_type = 1;

    optional int64 id = 2;
    optional string process_id = 3;
    optional int32 state = 4;
    optional int64 node_instance_counter = 5;
    optional string process_xml = 11;
    optional int64 parent_process_instance_id = 12;

    repeated SwimlaneContextInstance swimlane_context = 6;
    repeated NodeInstance node_instance = 7;
    repeated Variable variable = 8;
    repeated ExclusiveGroupInstance exclusive_group = 10;
    repeated string completedNodeIds = 13;
    repeated IterationLevel iterationLevels = 14;

    message SwimlaneContextInstance {
        optional string swimlane = 1;
        optional string actor_id = 2;
    }

    message NodeInstance {
        optional int64 id = 1;
        optional int64 node_id = 2;
        optional NodeInstanceContent content = 4;
        optional int32 level = 5;
    }

    message ExclusiveGroupInstance {
        repeated int64 group_node_instance_id = 1;
    }

    message NodeInstanceContent {
        optional NodeInstanceType type = 1;

        optional RuleSetNode rule_set = 2;
        optional HumanTaskNode human_task = 3;
        optional WorkItemNode work_item = 4;
        optional SubProcessNode sub_process = 5;
        optional MilestoneNode milestone = 6;
        optional EventNode event = 7;
        optional TimerNode timer = 8;
        optional JoinNode join = 9;
        optional StateNode state = 10;
        optional CompositeContextNode composite = 11;
        optional ForEachNode for_each = 12;

        message RuleSetNode {
            repeated int64 timer_instance_id = 1;
            repeated TextMapEntry mapEntry = 2;
            optional string rule_flow_group = 3;
            message TextMapEntry {
                optional string name = 1;
                optional string value = 2;
            }
        }
        message HumanTaskNode {
            optional int64 work_item_id = 1;
            repeated int64 timer_instance_id = 2;
        }
        message WorkItemNode {
            optional int64 work_item_id = 1;
            repeated int64 timer_instance_id = 2;
        }
        message SubProcessNode {
            optional int64 process_instance_id = 1;
            repeated int64 timer_instance_id = 2;
        }
        message MilestoneNode { repeated int64 timer_instance_id = 1; }
        message EventNode {}
        message TimerNode { optional int64 timer_id = 1; }
        message JoinNode {
            repeated JoinTrigger trigger = 1;
            message JoinTrigger {
                optional int64 node_id = 1;
                optional int32 counter = 2;
            }
        }
        message StateNode { repeated int64 timer_instance_id = 1; }
        message CompositeContextNode {
            repeated int64 timer_instance_id = 2;
            repeated Variable variable = 3;
            repeated NodeInstance node_instance = 4;
            repeated ExclusiveGroupInstance exclusive_group = 5;
            repeated IterationLevel iterationLevels = 6;
        }
        message ForEachNode {
            repeated NodeInstance node_instance = 1;
            repeated Variable variable = 2;
            repeated IterationLevel iterationLevels = 3;
        }
    }

    enum NodeInstanceType {
        RULE_SET_NODE = 0;
        HUMAN_TASK_NODE = 1;
        WORK_ITEM_NODE = 2;
        SUBPROCESS_NODE = 3;
        MILESTONE_NODE = 4;
        EVENT_NODE = 5;
        TIMER_NODE = 6;
        JOIN_NODE = 7;
        STATE_NODE = 8;
        COMPOSITE_CONTEXT_NODE = 9;
        FOR_EACH_NODE = 10;
        DYNAMIC_NODE = 11;
        EVENT_SUBPROCESS_NODE = 12;
    }
}

message Variable {
    optional string name = 1;
    // the actual object reference
    optional int32 strategy_index = 2;
    optional bytes value = 3;
}

extend org.drools.core.marshalling.Timers.Timer {
    optional ProcessTimer proc_timer = 100;
}

message WorkItem {
    optional int64 id = 1;
    optional int64 process_instances_id = 2;
    optional string name = 3;
    optional int32 state = 4;

    repeated Variable variable = 5;
}

message ProcessTimer {
    optional TimerInstance timer = 1;
    optional org.drools.core.marshalling.Trigger trigger = 2;

    message TimerInstance {
        optional int64 id = 1;
        optional int64 timer_id = 2;
        optional int64 delay = 3;
        optional int64 period = 4;
        optional int64 process_instance_id = 5;
        optional int64 activated_time = 6;
        optional int64 last_triggered = 7;
        optional int32 sessionId = 8;
    }
}

message IterationLevel {
    optional string id = 1;
    optional int32 level = 2;
}

