{
  "apiVersion": "modernedi.com/scenario/v1",
  "kind": "ScenarioDefinition",
  "metadata": {"namespace": "modernedi.examples", "key": "retail-order-lifecycle", "version": "1.0.0"},
  "spec": {
    "parameters": [
      {"id": "acknowledgmentCount", "type": "decimal", "required": true},
      {"id": "changeCount", "type": "decimal", "required": true},
      {"id": "changeResponseCount", "type": "decimal", "required": true},
      {"id": "shipmentCount", "type": "decimal", "required": true},
      {"id": "invoiceCount", "type": "decimal", "required": true},
      {"id": "expectedInvoiceTotal", "type": "decimal", "required": true}
    ],
    "actors": [{"id": "buyer"}, {"id": "supplier"}],
    "steps": [
      {
        "id": "purchaseOrder", "fromActor": "buyer", "toActor": "supplier",
        "transaction": {"standard": "X12", "transactionSet": "850", "businessUsage": "retail_purchase_order"},
        "occurrence": {"min": 1, "max": 1, "closure": {"kind": "fixed"}},
        "facts": [
          {"name": "purchaseOrderNumber", "type": "string", "cardinality": "one", "normalization": ["trim"], "sensitivity": "business"},
          {"name": "orderedItems", "type": "set", "elementType": "string", "cardinality": "one", "normalization": [], "sensitivity": "business"}
        ],
        "pipeline": [
          {"id": "exchange", "kind": "exchange"},
          {"id": "extract", "kind": "extract", "facts": ["purchaseOrderNumber", "orderedItems"]}
        ]
      },
      {
        "id": "purchaseOrderAcknowledgment", "fromActor": "supplier", "toActor": "buyer",
        "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": "acknowledgedItems", "type": "set", "elementType": "string", "cardinality": "one", "normalization": [], "sensitivity": "business"}
        ],
        "pipeline": [
          {"id": "exchange", "kind": "exchange"},
          {"id": "extract", "kind": "extract", "facts": ["purchaseOrderNumber", "acknowledgedItems"]}
        ]
      },
      {
        "id": "purchaseOrderChange", "fromActor": "buyer", "toActor": "supplier",
        "transaction": {"standard": "X12", "transactionSet": "860", "businessUsage": "purchase_order_change"},
        "occurrence": {"min": 1, "max": 3, "closure": {"kind": "expected_count", "parameter": "changeCount"}},
        "facts": [
          {"name": "purchaseOrderNumber", "type": "string", "cardinality": "one", "normalization": ["trim"], "sensitivity": "business"},
          {"name": "changeSequence", "type": "decimal", "cardinality": "one", "normalization": ["decimal_canonical"], "sensitivity": "business"},
          {"name": "effectiveTimestamp", "type": "timestamp", "cardinality": "one", "normalization": [], "sensitivity": "business"}
        ],
        "pipeline": [
          {"id": "exchange", "kind": "exchange"},
          {"id": "extract", "kind": "extract", "facts": ["purchaseOrderNumber", "changeSequence", "effectiveTimestamp"]}
        ]
      },
      {
        "id": "changeAcknowledgment", "fromActor": "supplier", "toActor": "buyer",
        "transaction": {"standard": "X12", "transactionSet": "865", "businessUsage": "purchase_order_change_acknowledgment"},
        "occurrence": {"min": 0, "max": 3, "closure": {"kind": "expected_count", "parameter": "changeResponseCount"}},
        "facts": [
          {"name": "purchaseOrderNumber", "type": "string", "cardinality": "one", "normalization": ["trim"], "sensitivity": "business"}
        ],
        "pipeline": [
          {"id": "exchange", "kind": "exchange"},
          {"id": "extract", "kind": "extract", "facts": ["purchaseOrderNumber"]}
        ]
      },
      {
        "id": "advanceShipNotice", "fromActor": "supplier", "toActor": "buyer",
        "transaction": {"standard": "X12", "transactionSet": "856", "businessUsage": "advance_ship_notice"},
        "occurrence": {"min": 1, "max": 4, "closure": {"kind": "expected_count", "parameter": "shipmentCount"}},
        "facts": [
          {"name": "purchaseOrderNumber", "type": "string", "cardinality": "one", "normalization": ["trim"], "sensitivity": "business"},
          {"name": "shipmentId", "type": "string", "cardinality": "one", "normalization": ["trim"], "sensitivity": "business"}
        ],
        "pipeline": [
          {"id": "exchange", "kind": "exchange"},
          {"id": "extract", "kind": "extract", "facts": ["purchaseOrderNumber", "shipmentId"]}
        ]
      },
      {
        "id": "invoice", "fromActor": "supplier", "toActor": "buyer",
        "transaction": {"standard": "X12", "transactionSet": "810", "businessUsage": "invoice"},
        "occurrence": {"min": 1, "max": 4, "closure": {"kind": "expected_count", "parameter": "invoiceCount"}},
        "facts": [
          {"name": "purchaseOrderNumber", "type": "string", "cardinality": "one", "normalization": ["trim"], "sensitivity": "business"},
          {"name": "invoiceAmount", "type": "decimal", "cardinality": "one", "normalization": ["decimal_canonical"], "sensitivity": "financial"}
        ],
        "pipeline": [
          {"id": "exchange", "kind": "exchange"},
          {"id": "extract", "kind": "extract", "facts": ["purchaseOrderNumber", "invoiceAmount"]}
        ]
      }
    ],
    "transitions": [
      {
        "id": "acknowledgesOrder", "fromStep": "purchaseOrder", "toStep": "purchaseOrderAcknowledgment", "relationship": "follows",
        "correlations": [
          {"id": "sameItems", "operator": "same_set", "left": {"kind": "fact", "stepId": "purchaseOrder", "fact": "orderedItems", "projection": "value"}, "right": {"kind": "fact", "stepId": "purchaseOrderAcknowledgment", "fact": "acknowledgedItems", "projection": "value"}}
        ],
        "matching": {"strategy": "correlate", "quantifiers": [{"kind": "every", "scope": "to"}], "unmatched": "record"}
      },
      {
        "id": "initialOrderChange", "fromStep": "purchaseOrder", "toStep": "purchaseOrderChange", "relationship": "supersedes",
        "correlations": [
          {"id": "sameOrder", "operator": "equal", "left": {"kind": "fact", "stepId": "purchaseOrder", "fact": "purchaseOrderNumber", "projection": "value"}, "right": {"kind": "fact", "stepId": "purchaseOrderChange", "fact": "purchaseOrderNumber", "projection": "value"}}
        ],
        "matching": {"strategy": "correlate", "quantifiers": [{"kind": "every", "scope": "to"}], "unmatched": "fail"},
        "effect": {"effectiveAt": {"kind": "observed_at"}, "downstream": "retain", "unmatched": "fail"}
      },
      {
        "id": "laterOrderChange", "fromStep": "purchaseOrderChange", "toStep": "purchaseOrderChange", "relationship": "supersedes",
        "correlations": [],
        "matching": {"strategy": "previous", "quantifiers": [{"kind": "every", "scope": "to"}], "unmatched": "record"},
        "effect": {"effectiveAt": {"kind": "value", "value": {"kind": "fact", "stepId": "purchaseOrderChange", "fact": "effectiveTimestamp", "projection": "value"}}, "downstream": "reevaluate", "unmatched": "record"}
      },
      {
        "id": "acknowledgesChange", "fromStep": "purchaseOrderChange", "toStep": "changeAcknowledgment", "relationship": "follows",
        "correlations": [
          {"id": "sameOrder", "operator": "equal", "left": {"kind": "fact", "stepId": "purchaseOrderChange", "fact": "purchaseOrderNumber", "projection": "value"}, "right": {"kind": "fact", "stepId": "changeAcknowledgment", "fact": "purchaseOrderNumber", "projection": "value"}}
        ],
        "matching": {"strategy": "correlate", "quantifiers": [{"kind": "every", "scope": "to"}], "unmatched": "record"}
      },
      {
        "id": "shipsChangedOrder", "fromStep": "purchaseOrderChange", "toStep": "advanceShipNotice", "relationship": "follows",
        "correlations": [
          {"id": "sameOrder", "operator": "equal", "left": {"kind": "fact", "stepId": "purchaseOrderChange", "fact": "purchaseOrderNumber", "projection": "value"}, "right": {"kind": "fact", "stepId": "advanceShipNotice", "fact": "purchaseOrderNumber", "projection": "value"}}
        ],
        "matching": {"strategy": "correlate", "quantifiers": [{"kind": "every", "scope": "to"}, {"kind": "exactly", "scope": "pairs", "count": 2}], "unmatched": "fail"}
      },
      {
        "id": "invoiceSettlesShipment", "fromStep": "advanceShipNotice", "toStep": "invoice", "relationship": "follows",
        "correlations": [],
        "matching": {"strategy": "position", "quantifiers": [{"kind": "every", "scope": "from"}, {"kind": "every", "scope": "to"}], "unmatched": "fail"}
      }
    ],
    "assertions": [
      {"id": "changeSequenceMonotonic", "operator": "monotonic", "left": {"kind": "fact", "stepId": "purchaseOrderChange", "fact": "changeSequence", "projection": "list"}},
      {"id": "shipmentIdsUnique", "operator": "unique", "left": {"kind": "fact", "stepId": "advanceShipNotice", "fact": "shipmentId", "projection": "list"}},
      {"id": "invoiceTotalMatches", "operator": "sum_equal", "left": {"kind": "fact", "stepId": "invoice", "fact": "invoiceAmount", "projection": "list"}, "right": {"kind": "parameter", "parameter": "expectedInvoiceTotal"}}
    ],
    "checkpoints": [],
    "branches": []
  }
}
