<?xml version="1.0" encoding="UTF-8"?>
<!-- Nafa: statut et reliquat d'une commande sur mesure, amounts in FCFA.

     The decisions nafa_commande_sur_mesure.bpmn evaluates in its business rule
     tasks. Each one sets statut to the order's status in Nafa (OrderStatus) and
     reliquat to what the client still owes:

       nafa_reliquat          reliquat = prixTotal - acompte
       nafa_commande_en_cours statut EN_COURS and the reliquat, when the order is taken
       nafa_commande_prete    statut PRET, the reliquat again (acompte may have grown
                                since the order) and messageClient, the WhatsApp text
                                « Votre commande est prête, reliquat : X FCFA »
       nafa_commande_soldee   statut SOLDE_LIVRE and a reliquat of 0, once delivered
                                and paid

     ANNULE is the merchant's to set, by finishing Confection with statut "ANNULE".
     The message reads the reliquat nafa_reliquat computed rather than
     prixTotal - acompte itself because a decision's answer may join only one
     variable to text. -->
<definitions
  xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/"
  xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/"
  xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
  xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
  id="def_nafa_commande_sur_mesure"
  name="Nafa : statut et reliquat d'une commande"
  namespace="http://priostack.com/nafa">

  <decision id="nafa_reliquat" name="Reliquat de la commande">
    <variable name="reliquat" typeRef="number"/>
    <literalExpression id="le_nafa_reliquat">
      <text>prixTotal - acompte</text>
    </literalExpression>
  </decision>

  <decision id="nafa_commande_en_cours" name="Commande en cours">
    <informationRequirement id="ir_en_cours_reliquat">
      <requiredDecision href="#nafa_reliquat"/>
    </informationRequirement>
    <decisionTable id="dt_nafa_commande_en_cours" hitPolicy="UNIQUE">
      <input id="in_en_cours_reliquat" label="Reliquat (FCFA)">
        <inputExpression id="ie_en_cours_reliquat" typeRef="number"><text>reliquat</text></inputExpression>
      </input>
      <output id="out_en_cours_statut" label="Statut" name="statut" typeRef="string"/>
      <output id="out_en_cours_reliquat" label="Reliquat (FCFA)" name="reliquat" typeRef="number"/>
      <rule id="r_en_cours">
        <inputEntry id="ie_en_cours_any"><text>-</text></inputEntry>
        <outputEntry id="oe_en_cours_statut"><text>"EN_COURS"</text></outputEntry>
        <outputEntry id="oe_en_cours_reliquat"><text>reliquat</text></outputEntry>
      </rule>
    </decisionTable>
  </decision>

  <decision id="nafa_commande_prete" name="Commande prête : message WhatsApp">
    <informationRequirement id="ir_prete_reliquat">
      <requiredDecision href="#nafa_reliquat"/>
    </informationRequirement>
    <decisionTable id="dt_nafa_commande_prete" hitPolicy="UNIQUE">
      <input id="in_prete_reliquat" label="Reliquat (FCFA)">
        <inputExpression id="ie_prete_reliquat" typeRef="number"><text>reliquat</text></inputExpression>
      </input>
      <output id="out_prete_statut" label="Statut" name="statut" typeRef="string"/>
      <output id="out_prete_reliquat" label="Reliquat (FCFA)" name="reliquat" typeRef="number"/>
      <output id="out_prete_message" label="Message WhatsApp" name="messageClient" typeRef="string"/>
      <rule id="r_prete">
        <inputEntry id="ie_prete_any"><text>-</text></inputEntry>
        <outputEntry id="oe_prete_statut"><text>"PRET"</text></outputEntry>
        <outputEntry id="oe_prete_reliquat"><text>reliquat</text></outputEntry>
        <outputEntry id="oe_prete_message"><text>"Votre commande est prête, reliquat : " + string(reliquat) + " FCFA"</text></outputEntry>
      </rule>
    </decisionTable>
  </decision>

  <decision id="nafa_commande_soldee" name="Commande livrée et soldée">
    <decisionTable id="dt_nafa_commande_soldee" hitPolicy="UNIQUE">
      <input id="in_soldee_reliquat" label="Reliquat (FCFA)">
        <inputExpression id="ie_soldee_reliquat" typeRef="number"><text>reliquat</text></inputExpression>
      </input>
      <output id="out_soldee_statut" label="Statut" name="statut" typeRef="string"/>
      <output id="out_soldee_reliquat" label="Reliquat (FCFA)" name="reliquat" typeRef="number"/>
      <rule id="r_soldee">
        <inputEntry id="ie_soldee_any"><text>-</text></inputEntry>
        <outputEntry id="oe_soldee_statut"><text>"SOLDE_LIVRE"</text></outputEntry>
        <outputEntry id="oe_soldee_reliquat"><text>0</text></outputEntry>
      </rule>
    </decisionTable>
  </decision>

  <dmndi:DMNDI>
    <dmndi:DMNDiagram>
      <dmndi:DMNShape dmnElementRef="nafa_reliquat">
        <dc:Bounds x="257" y="261" width="180" height="80"/>
      </dmndi:DMNShape>
      <dmndi:DMNShape dmnElementRef="nafa_commande_en_cours">
        <dc:Bounds x="157" y="81" width="180" height="80"/>
      </dmndi:DMNShape>
      <dmndi:DMNShape dmnElementRef="nafa_commande_prete">
        <dc:Bounds x="377" y="81" width="180" height="80"/>
      </dmndi:DMNShape>
      <dmndi:DMNShape dmnElementRef="nafa_commande_soldee">
        <dc:Bounds x="597" y="81" width="180" height="80"/>
      </dmndi:DMNShape>
      <dmndi:DMNEdge dmnElementRef="ir_en_cours_reliquat">
        <di:waypoint x="317" y="261"/>
        <di:waypoint x="247" y="161"/>
      </dmndi:DMNEdge>
      <dmndi:DMNEdge dmnElementRef="ir_prete_reliquat">
        <di:waypoint x="377" y="261"/>
        <di:waypoint x="467" y="161"/>
      </dmndi:DMNEdge>
    </dmndi:DMNDiagram>
  </dmndi:DMNDI>

</definitions>
