<?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:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="urn:example:reservation"
  xmlns:payload="urn:example:reservation:payload"
  xmlns:getriebe="https://tokenjanitor.github.io/getriebe/bpmn/extensions/v1"
  targetNamespace="urn:example:reservation">
  <bpmn:import namespace="urn:example:reservation:payload" location="reservation.xsd"
    importType="http://www.w3.org/2001/XMLSchema" />
  <bpmn:itemDefinition id="Text" structureRef="xs:string" />
  <bpmn:itemDefinition id="RequestPayload" structureRef="payload:ReservationRequest" />
  <bpmn:itemDefinition id="ResponsePayload" structureRef="payload:ReservationResponse" />
  <bpmn:message id="ReservationRequest.V1" itemRef="tns:RequestPayload" />
  <bpmn:message id="ReservationResponse.V1" itemRef="tns:ResponsePayload" />
  <bpmn:error id="WindowClosed" name="Delivery window closed" errorCode="DELIVERY_WINDOW_CLOSED" />
  <bpmn:interface id="Warehouse" name="Warehouse">
    <bpmn:operation id="ReserveSlot" name="Reserve slot">
      <bpmn:inMessageRef>tns:ReservationRequest.V1</bpmn:inMessageRef>
      <bpmn:outMessageRef>tns:ReservationResponse.V1</bpmn:outMessageRef>
      <bpmn:errorRef>tns:WindowClosed</bpmn:errorRef>
    </bpmn:operation>
  </bpmn:interface>
  <bpmn:resource id="reviewer" name="Reviewer" />
  <bpmn:process id="OrderDeliveryReservation" name="Order delivery reservation" isExecutable="true">
    <bpmn:property id="requestedSlot" itemSubjectRef="tns:Text" />
    <bpmn:property id="warehouse" itemSubjectRef="tns:Text" />
    <bpmn:property id="confirmedReservation" itemSubjectRef="tns:Text" />
    <bpmn:startEvent id="Start" name="Order ready for delivery" />
    <bpmn:exclusiveGateway id="SelectedSlot" />
    <bpmn:serviceTask id="Reserve" name="Reserve delivery slot" implementation="##unspecified"
      operationRef="tns:ReserveSlot" getriebe:connector="http-rest"
      getriebe:connectorVersion="1" getriebe:connection="inventory"
      getriebe:connectorConfig="{&quot;method&quot;:&quot;POST&quot;,&quot;path&quot;:&quot;delivery-reservations&quot;}"
      getriebe:connectorFaultRules="[{&quot;status&quot;:409,&quot;field&quot;:&quot;code&quot;,&quot;equals&quot;:&quot;slot_closed&quot;,&quot;errorCode&quot;:&quot;DELIVERY_WINDOW_CLOSED&quot;}]">
      <bpmn:ioSpecification>
        <bpmn:dataInput id="Request" itemSubjectRef="tns:RequestPayload" />
        <bpmn:dataOutput id="Response" itemSubjectRef="tns:ResponsePayload" />
        <bpmn:inputSet><bpmn:dataInputRefs>Request</bpmn:dataInputRefs></bpmn:inputSet>
        <bpmn:outputSet><bpmn:dataOutputRefs>Response</bpmn:dataOutputRefs></bpmn:outputSet>
      </bpmn:ioSpecification>
      <bpmn:dataInputAssociation>
        <bpmn:sourceRef>requestedSlot</bpmn:sourceRef>
        <bpmn:targetRef>Request</bpmn:targetRef>
        <bpmn:assignment>
          <bpmn:from xsi:type="bpmn:tFormalExpression">$requestedSlot</bpmn:from>
          <bpmn:to xsi:type="bpmn:tFormalExpression">$Request/slotId</bpmn:to>
        </bpmn:assignment>
      </bpmn:dataInputAssociation>
      <bpmn:dataInputAssociation>
        <bpmn:sourceRef>warehouse</bpmn:sourceRef>
        <bpmn:targetRef>Request</bpmn:targetRef>
        <bpmn:assignment>
          <bpmn:from xsi:type="bpmn:tFormalExpression">$warehouse</bpmn:from>
          <bpmn:to xsi:type="bpmn:tFormalExpression">$Request/warehouseId</bpmn:to>
        </bpmn:assignment>
      </bpmn:dataInputAssociation>
      <bpmn:dataOutputAssociation>
        <bpmn:sourceRef>Response</bpmn:sourceRef>
        <bpmn:targetRef>confirmedReservation</bpmn:targetRef>
        <bpmn:assignment>
          <bpmn:from xsi:type="bpmn:tFormalExpression">$Response/reservationId</bpmn:from>
          <bpmn:to xsi:type="bpmn:tFormalExpression">$confirmedReservation</bpmn:to>
        </bpmn:assignment>
      </bpmn:dataOutputAssociation>
    </bpmn:serviceTask>
    <bpmn:boundaryEvent id="CatchWindowClosed" attachedToRef="tns:Reserve">
      <bpmn:errorEventDefinition errorRef="tns:WindowClosed" />
    </bpmn:boundaryEvent>
    <bpmn:userTask id="ChooseAnotherSlot" name="Choose another delivery slot">
      <bpmn:ioSpecification>
        <bpmn:dataOutput id="AnotherSlot" name="slotId" itemSubjectRef="tns:Text" />
        <bpmn:inputSet />
        <bpmn:outputSet><bpmn:dataOutputRefs>AnotherSlot</bpmn:dataOutputRefs></bpmn:outputSet>
      </bpmn:ioSpecification>
      <bpmn:dataOutputAssociation>
        <bpmn:sourceRef>AnotherSlot</bpmn:sourceRef>
        <bpmn:targetRef>requestedSlot</bpmn:targetRef>
      </bpmn:dataOutputAssociation>
      <bpmn:potentialOwner><bpmn:resourceRef>tns:reviewer</bpmn:resourceRef></bpmn:potentialOwner>
    </bpmn:userTask>
    <bpmn:endEvent id="Reserved" name="Delivery slot reserved" />
    <bpmn:sequenceFlow id="RequestReservation" sourceRef="Start" targetRef="SelectedSlot" />
    <bpmn:sequenceFlow id="ReserveSelected" sourceRef="SelectedSlot" targetRef="Reserve" />
    <bpmn:sequenceFlow id="SlotReserved" sourceRef="Reserve" targetRef="Reserved" />
    <bpmn:sequenceFlow id="PickSlot" sourceRef="CatchWindowClosed" targetRef="ChooseAnotherSlot" />
    <bpmn:sequenceFlow id="SlotChanged" sourceRef="ChooseAnotherSlot" targetRef="SelectedSlot" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="ReservationDiagram">
    <bpmndi:BPMNPlane id="ReservationPlane" bpmnElement="OrderDeliveryReservation">
      <bpmndi:BPMNShape id="Start_di" bpmnElement="Start"><dc:Bounds x="118" y="141" width="36" height="36" /></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="SelectedSlot_di" bpmnElement="SelectedSlot"><dc:Bounds x="223" y="134" width="50" height="50" /></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Reserve_di" bpmnElement="Reserve"><dc:Bounds x="344" y="120" width="132" height="78" /></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="CatchWindowClosed_di" bpmnElement="CatchWindowClosed"><dc:Bounds x="423" y="179" width="36" height="36" /></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Reserved_di" bpmnElement="Reserved"><dc:Bounds x="565" y="141" width="36" height="36" /></bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="ChooseAnotherSlot_di" bpmnElement="ChooseAnotherSlot"><dc:Bounds x="348" y="286" width="160" height="79" /></bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="RequestReservation_di" bpmnElement="RequestReservation"><di:waypoint x="154" y="159" /><di:waypoint x="223" y="159" /></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="ReserveSelected_di" bpmnElement="ReserveSelected"><di:waypoint x="273" y="159" /><di:waypoint x="344" y="159" /></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SlotReserved_di" bpmnElement="SlotReserved"><di:waypoint x="476" y="159" /><di:waypoint x="565" y="159" /></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="PickSlot_di" bpmnElement="PickSlot"><di:waypoint x="441" y="215" /><di:waypoint x="441" y="286" /></bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SlotChanged_di" bpmnElement="SlotChanged"><di:waypoint x="348" y="325" /><di:waypoint x="248" y="325" /><di:waypoint x="248" y="184" /></bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
