{
  "apiVersion": 64,
  "status": "Active",
  "label": "Standard Contract Lifecycle Stamp",
  "description": "Maps PingCAP Contract business statuses to valid standard StatusCode categories before save.",
  "runAtomically": true,
  "start": {
    "triggerOrder": 200,
    "locationX": 40,
    "locationY": 0,
    "object": "Contract",
    "triggerType": "RecordBeforeSave",
    "recordTriggerType": "Update",
    "filterLogic": "1",
    "filters": [
      { "field": "Status", "operator": "IsChanged" }
    ],
    "connector": { "targetReference": "RouteStatusStamp" }
  },
  "decisions": [
    {
      "name": "RouteStatusStamp",
      "label": "Map business status to standard category",
      "locationX": 40,
      "locationY": 120,
      "defaultConnectorLabel": "Leave StatusCode unchanged",
      "rules": [
        {
          "name": "StatusActivated",
          "conditionLogic": "and",
          "conditions": [
            { "leftValueReference": "$Record.Status", "operator": "EqualTo", "rightValue": { "stringValue": "Activated" } }
          ],
          "connector": { "targetReference": "StampActivationFields" }
        },
        {
          "name": "StatusDraft",
          "conditionLogic": "and",
          "conditions": [
            { "leftValueReference": "$Record.Status", "operator": "EqualTo", "rightValue": { "stringValue": "Draft" } }
          ],
          "connector": { "targetReference": "SyncStatusCodeDraft" }
        },
        {
          "name": "StatusInReview",
          "conditionLogic": "and",
          "conditions": [
            { "leftValueReference": "$Record.Status", "operator": "EqualTo", "rightValue": { "stringValue": "In Review" } }
          ],
          "connector": { "targetReference": "SyncStatusCodeInApproval" }
        },
        {
          "name": "StatusEffective",
          "conditionLogic": "and",
          "conditions": [
            { "leftValueReference": "$Record.Status", "operator": "EqualTo", "rightValue": { "stringValue": "Effective" } }
          ],
          "connector": { "targetReference": "StampEffectiveFields" }
        },
        {
          "name": "StatusExpired",
          "conditionLogic": "and",
          "conditions": [
            { "leftValueReference": "$Record.Status", "operator": "EqualTo", "rightValue": { "stringValue": "Expired" } }
          ],
          "connector": { "targetReference": "SyncStatusCodeExpired" }
        },
        {
          "name": "StatusCancelled",
          "conditionLogic": "and",
          "conditions": [
            { "leftValueReference": "$Record.Status", "operator": "EqualTo", "rightValue": { "stringValue": "Cancelled" } }
          ],
          "connector": { "targetReference": "SyncStatusCodeTerminated" }
        }
      ]
    }
  ],
  "assignments": [
    {
      "name": "StampActivationFields",
      "label": "Stamp Contract activation fields",
      "locationX": 40,
      "locationY": 240,
      "assignmentItems": [
        {
          "assignToReference": "$Record.StatusCode",
          "operator": "Assign",
          "value": { "stringValue": "Activated" }
        },
        {
          "assignToReference": "$Record.ActivatedDate",
          "operator": "Assign",
          "value": { "elementReference": "$Flow.CurrentDateTime" }
        },
        {
          "assignToReference": "$Record.ActivatedById",
          "operator": "Assign",
          "value": { "elementReference": "$User.Id" }
        }
      ]
    },
    {
      "name": "StampEffectiveFields",
      "label": "Stamp Contract effective fields",
      "locationX": 220,
      "locationY": 240,
      "assignmentItems": [
        {
          "assignToReference": "$Record.StatusCode",
          "operator": "Assign",
          "value": { "stringValue": "Effective" }
        },
        {
          "assignToReference": "$Record.ActivatedDate",
          "operator": "Assign",
          "value": { "elementReference": "$Flow.CurrentDateTime" }
        },
        {
          "assignToReference": "$Record.ActivatedById",
          "operator": "Assign",
          "value": { "elementReference": "$User.Id" }
        }
      ]
    },
    {
      "name": "SyncStatusCodeDraft",
      "label": "Sync Contract category to Draft",
      "locationX": 400,
      "locationY": 240,
      "assignmentItems": [
        {
          "assignToReference": "$Record.StatusCode",
          "operator": "Assign",
          "value": { "stringValue": "Draft" }
        }
      ]
    },
    {
      "name": "SyncStatusCodeInApproval",
      "label": "Sync Contract category to InApproval",
      "locationX": 580,
      "locationY": 240,
      "assignmentItems": [
        {
          "assignToReference": "$Record.StatusCode",
          "operator": "Assign",
          "value": { "stringValue": "InApproval" }
        }
      ]
    },
    {
      "name": "SyncStatusCodeExpired",
      "label": "Sync Contract category to Expired",
      "locationX": 760,
      "locationY": 240,
      "assignmentItems": [
        {
          "assignToReference": "$Record.StatusCode",
          "operator": "Assign",
          "value": { "stringValue": "Expired" }
        }
      ]
    },
    {
      "name": "SyncStatusCodeTerminated",
      "label": "Sync Contract category to Terminated",
      "locationX": 940,
      "locationY": 240,
      "assignmentItems": [
        {
          "assignToReference": "$Record.StatusCode",
          "operator": "Assign",
          "value": { "stringValue": "Terminated" }
        }
      ]
    }
  ]
}
