<?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:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="@bpmnkit/core" exporterVersion="0.0.23" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.9.0">
  <bpmn:message id="Message_signature_completed" name="signature-completed">
    <bpmn:extensionElements>
      <zeebe:subscription correlationKey="=envelopeId"/>
    </bpmn:extensionElements>
  </bpmn:message>
  <bpmn:process id="document-signature" name="Document E-Signature" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="agreement-requested" name="Agreement requested">
      <bpmn:outgoing>Flow_agreement-requested_generate-document</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="generate-document" name="Generate agreement">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="document-generate"/>
        <zeebe:ioMapping>
          <zeebe:output source="=documentId" target="documentId"/>
        </zeebe:ioMapping>
        <zeebe:taskHeaders>
          <zeebe:header key="template" value="master-services-agreement"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_agreement-requested_generate-document</bpmn:incoming>
      <bpmn:outgoing>Flow_generate-document_send-envelope</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="send-envelope" name="Send for signature">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="esign-envelope-send"/>
        <zeebe:ioMapping>
          <zeebe:output source="=envelopeId" target="envelopeId"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_generate-document_send-envelope</bpmn:incoming>
      <bpmn:outgoing>Flow_send-envelope_await-signature</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:receiveTask id="await-signature" name="Await signing outcome" messageRef="Message_signature_completed">
      <bpmn:incoming>Flow_send-envelope_await-signature</bpmn:incoming>
      <bpmn:outgoing>Flow_await-signature_signed</bpmn:outgoing>
    </bpmn:receiveTask>
    <bpmn:boundaryEvent id="signature-expired" name="14 days" attachedToRef="await-signature">
      <bpmn:outgoing>Flow_signature-expired_void-envelope</bpmn:outgoing>
      <bpmn:timerEventDefinition>
        <bpmn:timeDuration>P14D</bpmn:timeDuration>
      </bpmn:timerEventDefinition>
    </bpmn:boundaryEvent>
    <bpmn:serviceTask id="void-envelope" name="Void envelope">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="esign-envelope-void"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_signature-expired_void-envelope</bpmn:incoming>
      <bpmn:outgoing>Flow_void-envelope_envelope-expired</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="envelope-expired" name="Envelope expired">
      <bpmn:incoming>Flow_void-envelope_envelope-expired</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:exclusiveGateway id="signed" name="Signed?" default="Flow_signed_notify-owner">
      <bpmn:incoming>Flow_await-signature_signed</bpmn:incoming>
      <bpmn:outgoing>Flow_signed_archive-document</bpmn:outgoing>
      <bpmn:outgoing>Flow_signed_notify-owner</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="archive-document" name="Archive signed agreement">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="dms-archive"/>
        <zeebe:ioMapping>
          <zeebe:output source="=archiveId" target="archiveId"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_signed_archive-document</bpmn:incoming>
      <bpmn:outgoing>Flow_archive-document_agreement-signed</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="agreement-signed" name="Agreement signed">
      <bpmn:incoming>Flow_archive-document_agreement-signed</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:serviceTask id="notify-owner" name="Notify owner: declined">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="owner-notify"/>
        <zeebe:taskHeaders>
          <zeebe:header key="template" value="signature-declined"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_signed_notify-owner</bpmn:incoming>
      <bpmn:outgoing>Flow_notify-owner_agreement-declined</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="agreement-declined" name="Agreement declined">
      <bpmn:incoming>Flow_notify-owner_agreement-declined</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_agreement-requested_generate-document" sourceRef="agreement-requested" targetRef="generate-document"/>
    <bpmn:sequenceFlow id="Flow_generate-document_send-envelope" sourceRef="generate-document" targetRef="send-envelope"/>
    <bpmn:sequenceFlow id="Flow_send-envelope_await-signature" sourceRef="send-envelope" targetRef="await-signature"/>
    <bpmn:sequenceFlow id="Flow_signature-expired_void-envelope" sourceRef="signature-expired" targetRef="void-envelope"/>
    <bpmn:sequenceFlow id="Flow_void-envelope_envelope-expired" sourceRef="void-envelope" targetRef="envelope-expired"/>
    <bpmn:sequenceFlow id="Flow_await-signature_signed" sourceRef="await-signature" targetRef="signed"/>
    <bpmn:sequenceFlow id="Flow_signed_archive-document" sourceRef="signed" targetRef="archive-document" name="signed">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=signatureStatus = "signed"</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_archive-document_agreement-signed" sourceRef="archive-document" targetRef="agreement-signed"/>
    <bpmn:sequenceFlow id="Flow_signed_notify-owner" sourceRef="signed" targetRef="notify-owner" name="declined"/>
    <bpmn:sequenceFlow id="Flow_notify-owner_agreement-declined" sourceRef="notify-owner" targetRef="agreement-declined"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="document-signature_di">
    <bpmndi:BPMNPlane id="document-signature_di_plane" bpmnElement="document-signature">
      <bpmndi:BPMNShape id="agreement-requested_di" bpmnElement="agreement-requested">
        <dc:Bounds x="69" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="82" width="133" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="generate-document_di" bpmnElement="generate-document">
        <dc:Bounds x="205" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="send-envelope_di" bpmnElement="send-envelope">
        <dc:Bounds x="405" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="await-signature_di" bpmnElement="await-signature">
        <dc:Bounds x="605" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="signature-expired_di" bpmnElement="signature-expired">
        <dc:Bounds x="637" y="82" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="630" y="122" width="49" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="void-envelope_di" bpmnElement="void-envelope">
        <dc:Bounds x="805" y="340" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="envelope-expired_di" bpmnElement="envelope-expired">
        <dc:Bounds x="1037" y="362" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="999" y="402" width="112" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="signed_di" bpmnElement="signed">
        <dc:Bounds x="830" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="830" y="89" width="49" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="archive-document_di" bpmnElement="archive-document">
        <dc:Bounds x="1005" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="agreement-signed_di" bpmnElement="agreement-signed">
        <dc:Bounds x="1205" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1167" y="242" width="112" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="notify-owner_di" bpmnElement="notify-owner">
        <dc:Bounds x="1005" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="agreement-declined_di" bpmnElement="agreement-declined">
        <dc:Bounds x="1205" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1160" y="82" width="126" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_agreement-requested_generate-document_di" bpmnElement="Flow_agreement-requested_generate-document">
        <di:waypoint x="105" y="60"/>
        <di:waypoint x="205" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_generate-document_send-envelope_di" bpmnElement="Flow_generate-document_send-envelope">
        <di:waypoint x="305" y="60"/>
        <di:waypoint x="405" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_send-envelope_await-signature_di" bpmnElement="Flow_send-envelope_await-signature">
        <di:waypoint x="505" y="60"/>
        <di:waypoint x="605" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_signature-expired_void-envelope_di" bpmnElement="Flow_signature-expired_void-envelope">
        <di:waypoint x="655" y="118"/>
        <di:waypoint x="655" y="380"/>
        <di:waypoint x="805" y="380"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_void-envelope_envelope-expired_di" bpmnElement="Flow_void-envelope_envelope-expired">
        <di:waypoint x="905" y="380"/>
        <di:waypoint x="1037" y="380"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_await-signature_signed_di" bpmnElement="Flow_await-signature_signed">
        <di:waypoint x="705" y="60"/>
        <di:waypoint x="830" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_signed_archive-document_di" bpmnElement="Flow_signed_archive-document">
        <di:waypoint x="855" y="85"/>
        <di:waypoint x="855" y="220"/>
        <di:waypoint x="1005" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="909" y="196" width="42" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_archive-document_agreement-signed_di" bpmnElement="Flow_archive-document_agreement-signed">
        <di:waypoint x="1105" y="220"/>
        <di:waypoint x="1205" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_signed_notify-owner_di" bpmnElement="Flow_signed_notify-owner">
        <di:waypoint x="880" y="60"/>
        <di:waypoint x="1005" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="914" y="36" width="56" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_notify-owner_agreement-declined_di" bpmnElement="Flow_notify-owner_agreement-declined">
        <di:waypoint x="1105" y="60"/>
        <di:waypoint x="1205" y="60"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

