<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" id="definitions" name="Book purchase proposal" targetNamespace="http://bpmn.io/schema/bpmn" exporter="tok" exporterVersion="1.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.10.0">
  <bpmn:message id="Message_Delivery" name="Delivery">
    <bpmn:extensionElements>
      <zeebe:subscription correlationKey="=orderNumber" />
    </bpmn:extensionElements>
  </bpmn:message>
  <bpmn:process id="book-purchase" name="Book purchase proposal" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0" />
    </bpmn:extensionElements>
    <bpmn:startEvent id="proposed" name="Proposal submitted">
      <bpmn:extensionElements>
        <zeebe:formDefinition formId="f-proposal" />
      </bpmn:extensionElements>
    </bpmn:startEvent>
    <bpmn:businessRuleTask id="mode" name="Determine approval mode">
      <bpmn:extensionElements>
        <zeebe:calledDecision decisionId="approval-mode" resultVariable="mode" />
      </bpmn:extensionElements>
    </bpmn:businessRuleTask>
    <bpmn:exclusiveGateway id="needs" name="Manager approval needed?" default="f-needs-merge" />
    <bpmn:userTask id="approve" name="Approve proposal">
      <bpmn:extensionElements>
        <zeebe:userTask />
        <zeebe:formDefinition formId="f-approval" />
        <zeebe:assignmentDefinition candidateGroups="acquisitions" />
        <zeebe:taskSchedule dueDate="=now() + duration(&quot;P7D&quot;)" />
        <zeebe:priorityDefinition priority="70" />
      </bpmn:extensionElements>
    </bpmn:userTask>
    <bpmn:boundaryEvent id="expired" name="7 days passed" attachedToRef="approve">
      <bpmn:timerEventDefinition id="expired-def">
        <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">P7D</bpmn:timeDuration>
      </bpmn:timerEventDefinition>
    </bpmn:boundaryEvent>
    <bpmn:exclusiveGateway id="agreed" name="Approved?" default="f-agreed-rejected" />
    <bpmn:exclusiveGateway id="merge" />
    <bpmn:scriptTask id="cost" name="Compute cost">
      <bpmn:extensionElements>
        <zeebe:script expression="=price + 12.5" resultVariable="cost" />
      </bpmn:extensionElements>
    </bpmn:scriptTask>
    <bpmn:serviceTask id="order" name="Order from supplier">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="order-book" retries="3" />
        <zeebe:ioMapping>
          <zeebe:input source="=title" target="title" />
          <zeebe:input source="=cost" target="amount" />
          <zeebe:output source="=order.number" target="orderNumber" />
        </zeebe:ioMapping>
        <zeebe:taskHeaders>
          <zeebe:header key="channel" value="api" />
          <zeebe:header key="supplier" value="central" />
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
    </bpmn:serviceTask>
    <bpmn:intermediateCatchEvent id="delivered" name="Book delivered">
      <bpmn:messageEventDefinition id="delivered-def" messageRef="Message_Delivery" />
    </bpmn:intermediateCatchEvent>
    <bpmn:endEvent id="done" name="Purchase completed" />
    <bpmn:endEvent id="rejected" name="Proposal rejected" />
    <bpmn:endEvent id="lapsed" name="Proposal lapsed" />
    <bpmn:sequenceFlow id="f-proposed-mode" sourceRef="proposed" targetRef="mode" />
    <bpmn:sequenceFlow id="f-mode-needs" sourceRef="mode" targetRef="needs" />
    <bpmn:sequenceFlow id="f-needs-approve" name="yes" sourceRef="needs" targetRef="approve">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=mode = "manager"</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="f-needs-merge" name="no" sourceRef="needs" targetRef="merge" />
    <bpmn:sequenceFlow id="f-approve-agreed" sourceRef="approve" targetRef="agreed" />
    <bpmn:sequenceFlow id="f-agreed-merge" name="yes" sourceRef="agreed" targetRef="merge">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=approved = true</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="f-agreed-rejected" name="no" sourceRef="agreed" targetRef="rejected" />
    <bpmn:sequenceFlow id="f-expired-lapsed" sourceRef="expired" targetRef="lapsed" />
    <bpmn:sequenceFlow id="f-merge-cost" sourceRef="merge" targetRef="cost" />
    <bpmn:sequenceFlow id="f-cost-order" sourceRef="cost" targetRef="order" />
    <bpmn:sequenceFlow id="f-order-delivered" sourceRef="order" targetRef="delivered" />
    <bpmn:sequenceFlow id="f-delivered-done" sourceRef="delivered" targetRef="done" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="book-purchase">
      <bpmndi:BPMNShape id="proposed_di" bpmnElement="proposed">
        <dc:Bounds x="30" y="52" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="-3" y="93" width="102" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="mode_di" bpmnElement="mode">
        <dc:Bounds x="116" y="30" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="needs_di" bpmnElement="needs" isMarkerVisible="true">
        <dc:Bounds x="266" y="45" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="246" y="100" width="90" height="23" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="approve_di" bpmnElement="approve">
        <dc:Bounds x="366" y="30" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="agreed_di" bpmnElement="agreed" isMarkerVisible="true">
        <dc:Bounds x="516" y="45" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="515" y="100" width="52" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="merge_di" bpmnElement="merge" isMarkerVisible="true">
        <dc:Bounds x="616" y="45" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="cost_di" bpmnElement="cost">
        <dc:Bounds x="716" y="30" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="order_di" bpmnElement="order">
        <dc:Bounds x="866" y="30" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="delivered_di" bpmnElement="delivered">
        <dc:Bounds x="1016" y="52" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="994" y="93" width="80" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="done_di" bpmnElement="done">
        <dc:Bounds x="1102" y="52" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1069" y="93" width="102" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="rejected_di" bpmnElement="rejected">
        <dc:Bounds x="623" y="160" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="593" y="201" width="96" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="lapsed_di" bpmnElement="lapsed">
        <dc:Bounds x="523" y="160" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="499" y="201" width="84" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="expired_di" bpmnElement="expired">
        <dc:Bounds x="418" y="92" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="357" y="131" width="74" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="f-proposed-mode_di" bpmnElement="f-proposed-mode">
        <di:waypoint x="66" y="70" />
        <di:waypoint x="116" y="70" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-mode-needs_di" bpmnElement="f-mode-needs">
        <di:waypoint x="216" y="70" />
        <di:waypoint x="266" y="70" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-needs-approve_di" bpmnElement="f-needs-approve">
        <di:waypoint x="316" y="70" />
        <di:waypoint x="366" y="70" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="323" y="55" width="18" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-needs-merge_di" bpmnElement="f-needs-merge">
        <di:waypoint x="291" y="45" />
        <di:waypoint x="291" y="30" />
        <di:waypoint x="591" y="30" />
        <di:waypoint x="591" y="70" />
        <di:waypoint x="616" y="70" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="299" y="15" width="12" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-approve-agreed_di" bpmnElement="f-approve-agreed">
        <di:waypoint x="466" y="70" />
        <di:waypoint x="516" y="70" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-agreed-merge_di" bpmnElement="f-agreed-merge">
        <di:waypoint x="566" y="70" />
        <di:waypoint x="616" y="70" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="573" y="55" width="18" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-agreed-rejected_di" bpmnElement="f-agreed-rejected">
        <di:waypoint x="566" y="70" />
        <di:waypoint x="591" y="70" />
        <di:waypoint x="591" y="178" />
        <di:waypoint x="623" y="178" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="597" y="80" width="12" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-expired-lapsed_di" bpmnElement="f-expired-lapsed">
        <di:waypoint x="436" y="128" />
        <di:waypoint x="436" y="178" />
        <di:waypoint x="523" y="178" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-merge-cost_di" bpmnElement="f-merge-cost">
        <di:waypoint x="666" y="70" />
        <di:waypoint x="716" y="70" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-cost-order_di" bpmnElement="f-cost-order">
        <di:waypoint x="816" y="70" />
        <di:waypoint x="866" y="70" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-order-delivered_di" bpmnElement="f-order-delivered">
        <di:waypoint x="966" y="70" />
        <di:waypoint x="1016" y="70" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-delivered-done_di" bpmnElement="f-delivered-done">
        <di:waypoint x="1052" y="70" />
        <di:waypoint x="1102" y="70" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
