<?xml version="1.0" encoding="UTF-8"?>
<!-- Customer Complaint Handling (template customer-complaint).

     Started with: customerId, channel, subject.

     Complaint received
       -> Log and set the priority   user task; complete with priority = "high" or "normal"
       -> High priority?             yes -> Resolve within 4 hours, else Resolve within 2 days
       -> Resolve within 4 hours     user task; after 4 hours (timer PT4H) it is taken away
                                     and goes to Escalated: team lead resolves
       -> Resolve within 2 days      user task; after 2 days (timer P2D), the same
       -> Escalated: team lead resolves   user task
       -> Reply to the customer      user task
       -> Closed

     The server fires due timers every 30 seconds. The 4 hours and 2 days are the
     SLA: change them on the two timer events.

     The answers are variables their steps are completed with: priority. The
     template's sample variables start each of them as null, so a step closed
     without its answer takes the safe branch. A run started without them stops with
     an incident at the first gateway whose variable was never set, because the
     engine never reads a missing variable as a no, and the hosted API cannot resume
     a run in INCIDENT. -->
<definitions
  xmlns="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:zeebe="http://camunda.org/schema/zeebe/1.0"
  targetNamespace="http://priostack.com/templates"
  id="def_customer_complaint">

  <process id="customer_complaint" name="Customer Complaint Handling" isExecutable="true">
    <documentation>A customer complaint from intake to reply: a priority set at intake, a resolution within 4 hours for a high-priority complaint or 2 days otherwise, and the team lead taking over when that time runs out.</documentation>

    <startEvent id="complaint_received" name="Complaint received"/>

    <userTask id="log_and_classify" name="Log and set the priority">
      <documentation>Record the complaint and complete with priority = "high" (the customer is losing money or service) or "normal".</documentation>
    </userTask>

    <exclusiveGateway id="gw_priority" name="High priority?" default="f_normal"/>

    <userTask id="resolve" name="Resolve within 2 days">
      <documentation>Find the cause and fix it for the customer. Complete with resolution = what was done.</documentation>
    </userTask>

    <boundaryEvent id="sla_normal" name="2 days passed" attachedToRef="resolve" cancelActivity="true">
      <outgoing>f_sla_normal_missed</outgoing>
      <timerEventDefinition>
        <timeDuration xsi:type="tFormalExpression">P2D</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>

    <userTask id="resolve_urgent" name="Resolve within 4 hours">
      <documentation>A high-priority complaint. Complete with resolution = what was done.</documentation>
    </userTask>

    <boundaryEvent id="sla_urgent" name="4 hours passed" attachedToRef="resolve_urgent" cancelActivity="true">
      <outgoing>f_sla_urgent_missed</outgoing>
      <timerEventDefinition>
        <timeDuration xsi:type="tFormalExpression">PT4H</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>

    <userTask id="escalated" name="Escalated: team lead resolves">
      <documentation>The resolution time ran out. The team lead takes the complaint over, resolves it, and completes with resolution.</documentation>
    </userTask>

    <userTask id="reply" name="Reply to the customer">
      <documentation>Tell the customer what was done, on the channel they used.</documentation>
    </userTask>

    <endEvent id="closed" name="Closed"/>

    <sequenceFlow id="f_received" sourceRef="complaint_received" targetRef="log_and_classify"/>
    <sequenceFlow id="f_classified" sourceRef="log_and_classify" targetRef="gw_priority"/>
    <sequenceFlow id="f_urgent" name="high" sourceRef="gw_priority" targetRef="resolve_urgent">
      <conditionExpression xsi:type="tFormalExpression">priority = "high"</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_normal" name="normal" sourceRef="gw_priority" targetRef="resolve"/>
    <sequenceFlow id="f_resolved" sourceRef="resolve" targetRef="reply"/>
    <sequenceFlow id="f_resolved_urgent" sourceRef="resolve_urgent" targetRef="reply"/>
    <sequenceFlow id="f_sla_normal_missed" sourceRef="sla_normal" targetRef="escalated"/>
    <sequenceFlow id="f_sla_urgent_missed" sourceRef="sla_urgent" targetRef="escalated"/>
    <sequenceFlow id="f_escalation_resolved" sourceRef="escalated" targetRef="reply"/>
    <sequenceFlow id="f_replied" sourceRef="reply" targetRef="closed"/>
  </process>

  <bpmndi:BPMNDiagram id="diagram_customer_complaint">
    <bpmndi:BPMNPlane id="plane_customer_complaint" bpmnElement="customer_complaint">
      <bpmndi:BPMNShape id="shape_complaint_received" bpmnElement="complaint_received">
        <dc:Bounds x="82" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_log_and_classify" bpmnElement="log_and_classify">
        <dc:Bounds x="215" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_priority" bpmnElement="gw_priority" isMarkerVisible="true">
        <dc:Bounds x="415" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_resolve" bpmnElement="resolve">
        <dc:Bounds x="555" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_sla_normal" bpmnElement="sla_normal">
        <dc:Bounds x="622" y="142" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_resolve_urgent" bpmnElement="resolve_urgent">
        <dc:Bounds x="555" y="220" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_sla_urgent" bpmnElement="sla_urgent">
        <dc:Bounds x="622" y="282" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_escalated" bpmnElement="escalated">
        <dc:Bounds x="725" y="360" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_reply" bpmnElement="reply">
        <dc:Bounds x="895" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_closed" bpmnElement="closed">
        <dc:Bounds x="1102" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge_f_received" bpmnElement="f_received">
        <di:waypoint x="118" y="120"/>
        <di:waypoint x="215" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_classified" bpmnElement="f_classified">
        <di:waypoint x="325" y="120"/>
        <di:waypoint x="415" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_urgent" bpmnElement="f_urgent">
        <di:waypoint x="440" y="145"/>
        <di:waypoint x="440" y="260"/>
        <di:waypoint x="555" y="260"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_normal" bpmnElement="f_normal">
        <di:waypoint x="465" y="120"/>
        <di:waypoint x="555" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_resolved" bpmnElement="f_resolved">
        <di:waypoint x="665" y="120"/>
        <di:waypoint x="895" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_resolved_urgent" bpmnElement="f_resolved_urgent">
        <di:waypoint x="665" y="260"/>
        <di:waypoint x="780" y="260"/>
        <di:waypoint x="780" y="120"/>
        <di:waypoint x="895" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_sla_normal_missed" bpmnElement="f_sla_normal_missed">
        <di:waypoint x="640" y="178"/>
        <di:waypoint x="640" y="200"/>
        <di:waypoint x="695" y="200"/>
        <di:waypoint x="695" y="400"/>
        <di:waypoint x="725" y="400"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_sla_urgent_missed" bpmnElement="f_sla_urgent_missed">
        <di:waypoint x="640" y="318"/>
        <di:waypoint x="640" y="340"/>
        <di:waypoint x="695" y="340"/>
        <di:waypoint x="695" y="400"/>
        <di:waypoint x="725" y="400"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_escalation_resolved" bpmnElement="f_escalation_resolved">
        <di:waypoint x="835" y="400"/>
        <di:waypoint x="865" y="400"/>
        <di:waypoint x="865" y="120"/>
        <di:waypoint x="895" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_replied" bpmnElement="f_replied">
        <di:waypoint x="1005" y="120"/>
        <di:waypoint x="1102" y="120"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
