{
  "$schema": "https://www.modernedi.com/docs/scenarios/schemas/scenario-definition-v1.schema.json",
  "apiVersion": "modernedi.com/scenario/v1",
  "kind": "ScenarioDefinition",
  "metadata": {
    "namespace": "modernedi.examples",
    "key": "supplier-order-fulfillment",
    "version": "1.0.0"
  },
  "spec": {
    "parameters": [
      {
        "id": "acknowledgmentCount",
        "type": "decimal",
        "required": true
      }
    ],
    "actors": [
      {
        "id": "retailer"
      },
      {
        "id": "supplier"
      }
    ],
    "steps": [
      {
        "id": "purchaseOrder",
        "fromActor": "retailer",
        "toActor": "supplier",
        "transaction": {
          "standard": "X12",
          "transactionSet": "850",
          "businessUsage": "purchase_order"
        },
        "occurrence": {
          "min": 1,
          "max": 1,
          "closure": {
            "kind": "fixed"
          }
        },
        "facts": [
          {
            "name": "purchaseOrderNumber",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "lineKeys",
            "type": "list",
            "elementType": "string",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "quantities",
            "type": "list",
            "elementType": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "linesValid",
            "type": "boolean",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "unitPrices",
            "type": "list",
            "elementType": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "financial"
          },
          {
            "name": "orderTotal",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [
              "decimal_canonical"
            ],
            "sensitivity": "financial"
          },
          {
            "name": "currency",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "purchaseOrderNumber",
              "lineKeys",
              "quantities",
              "linesValid",
              "unitPrices",
              "orderTotal",
              "currency"
            ]
          },
          {
            "id": "acknowledgmentDecision",
            "kind": "checkpoint",
            "checkpoint": "orderObserved"
          }
        ]
      },
      {
        "id": "purchaseOrderAcknowledgment",
        "fromActor": "supplier",
        "toActor": "retailer",
        "transaction": {
          "standard": "X12",
          "transactionSet": "855",
          "businessUsage": "purchase_order_acknowledgment"
        },
        "occurrence": {
          "min": 0,
          "max": 1,
          "closure": {
            "kind": "expected_count",
            "parameter": "acknowledgmentCount"
          }
        },
        "facts": [
          {
            "name": "purchaseOrderNumber",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "acknowledgmentCode",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "purchaseOrderNumber",
              "acknowledgmentCode"
            ]
          }
        ]
      },
      {
        "id": "advanceShipNotice",
        "fromActor": "supplier",
        "toActor": "retailer",
        "transaction": {
          "standard": "X12",
          "transactionSet": "856",
          "businessUsage": "advance_ship_notice"
        },
        "occurrence": {
          "min": 1,
          "max": 1,
          "closure": {
            "kind": "fixed"
          }
        },
        "facts": [
          {
            "name": "purchaseOrderNumber",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "shipmentId",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "lineKeys",
            "type": "list",
            "elementType": "string",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "quantities",
            "type": "list",
            "elementType": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "linesValid",
            "type": "boolean",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "purchaseOrderNumber",
              "shipmentId",
              "lineKeys",
              "quantities",
              "linesValid"
            ]
          }
        ]
      },
      {
        "id": "invoice",
        "fromActor": "supplier",
        "toActor": "retailer",
        "transaction": {
          "standard": "X12",
          "transactionSet": "810",
          "businessUsage": "invoice"
        },
        "occurrence": {
          "min": 1,
          "max": 1,
          "closure": {
            "kind": "fixed"
          }
        },
        "facts": [
          {
            "name": "purchaseOrderNumber",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "shipmentId",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "lineKeys",
            "type": "list",
            "elementType": "string",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "quantities",
            "type": "list",
            "elementType": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "linesValid",
            "type": "boolean",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "unitPrices",
            "type": "list",
            "elementType": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "financial"
          },
          {
            "name": "lineTotal",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [
              "decimal_canonical"
            ],
            "sensitivity": "financial"
          },
          {
            "name": "invoiceTotal",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [
              "decimal_canonical"
            ],
            "sensitivity": "financial"
          },
          {
            "name": "currency",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "purchaseOrderNumber",
              "shipmentId",
              "lineKeys",
              "quantities",
              "linesValid",
              "unitPrices",
              "lineTotal",
              "invoiceTotal",
              "currency"
            ]
          }
        ]
      }
    ],
    "transitions": [
      {
        "id": "acknowledgmentForOrder",
        "fromStep": "purchaseOrder",
        "toStep": "purchaseOrderAcknowledgment",
        "relationship": "follows",
        "within": "P2D",
        "correlations": [
          {
            "id": "purchaseOrderNumber",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "purchaseOrder",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "purchaseOrderAcknowledgment",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            }
          ],
          "unmatched": "fail"
        }
      },
      {
        "id": "shipmentForOrder",
        "fromStep": "purchaseOrder",
        "toStep": "advanceShipNotice",
        "relationship": "follows",
        "within": "P7D",
        "correlations": [
          {
            "id": "purchaseOrderNumber",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "purchaseOrder",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "advanceShipNotice",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            }
          ],
          "unmatched": "fail"
        }
      },
      {
        "id": "invoiceForOrder",
        "fromStep": "purchaseOrder",
        "toStep": "invoice",
        "relationship": "follows",
        "within": "P30D",
        "correlations": [
          {
            "id": "purchaseOrderNumber",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "purchaseOrder",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "invoice",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            }
          ],
          "unmatched": "fail"
        }
      },
      {
        "id": "invoiceForShipment",
        "fromStep": "advanceShipNotice",
        "toStep": "invoice",
        "relationship": "follows",
        "within": "P7D",
        "correlations": [
          {
            "id": "purchaseOrderNumber",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "advanceShipNotice",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "invoice",
              "fact": "purchaseOrderNumber",
              "projection": "value"
            }
          },
          {
            "id": "shipmentId",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "advanceShipNotice",
              "fact": "shipmentId",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "invoice",
              "fact": "shipmentId",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            }
          ],
          "unmatched": "fail"
        }
      }
    ],
    "assertions": [
      {
        "id": "purchaseOrderLineKeysUnique",
        "operator": "unique",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "lineKeys",
          "projection": "value"
        }
      },
      {
        "id": "purchaseOrderLinesValid",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "linesValid",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "boolean",
          "value": true
        }
      },
      {
        "id": "advanceShipNoticeLineKeysUnique",
        "operator": "unique",
        "left": {
          "kind": "fact",
          "stepId": "advanceShipNotice",
          "fact": "lineKeys",
          "projection": "value"
        }
      },
      {
        "id": "advanceShipNoticeLinesValid",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "advanceShipNotice",
          "fact": "linesValid",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "boolean",
          "value": true
        }
      },
      {
        "id": "invoiceLineKeysUnique",
        "operator": "unique",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "lineKeys",
          "projection": "value"
        }
      },
      {
        "id": "invoiceLinesValid",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "linesValid",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "boolean",
          "value": true
        }
      },
      {
        "id": "acknowledgmentAcceptsWithoutChanges",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrderAcknowledgment",
          "fact": "acknowledgmentCode",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "string",
          "value": "AK"
        }
      },
      {
        "id": "advanceShipNoticeLineKeysMatchOrder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "lineKeys",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "advanceShipNotice",
          "fact": "lineKeys",
          "projection": "value"
        }
      },
      {
        "id": "advanceShipNoticeQuantitiesMatchOrder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "quantities",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "advanceShipNotice",
          "fact": "quantities",
          "projection": "value"
        }
      },
      {
        "id": "invoiceLineKeysMatchOrder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "lineKeys",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "lineKeys",
          "projection": "value"
        }
      },
      {
        "id": "invoiceQuantitiesMatchOrder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "quantities",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "quantities",
          "projection": "value"
        }
      },
      {
        "id": "invoicePricesMatchOrder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "unitPrices",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "unitPrices",
          "projection": "value"
        }
      },
      {
        "id": "orderUsesUsd",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "currency",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "string",
          "value": "USD"
        }
      },
      {
        "id": "invoiceCurrencyMatchesOrder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "currency",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "currency",
          "projection": "value"
        }
      },
      {
        "id": "invoiceTotalMatchesLines",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "lineTotal",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "invoiceTotal",
          "projection": "value"
        }
      },
      {
        "id": "invoiceTotalMatchesOrder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "orderTotal",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "invoiceTotal",
          "projection": "value"
        }
      }
    ],
    "checkpoints": [
      {
        "id": "orderObserved"
      }
    ],
    "branches": [
      {
        "id": "acknowledgmentChoice",
        "mode": "at_most_one",
        "checkpoint": "orderObserved",
        "alternatives": [
          {
            "id": "expectAcknowledgment",
            "kind": "when",
            "transitionId": "acknowledgmentForOrder",
            "conditions": [
              {
                "id": "acknowledgmentExpected",
                "operator": "equal",
                "left": {
                  "kind": "parameter",
                  "parameter": "acknowledgmentCount"
                },
                "right": {
                  "kind": "literal",
                  "type": "decimal",
                  "value": 1
                }
              }
            ]
          }
        ]
      }
    ]
  }
}
