{
  "$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-partial-fulfillment",
    "version": "1.0.0"
  },
  "spec": {
    "parameters": [],
    "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": "purchaseOrderAcknowledgment",
        "fromActor": "supplier",
        "toActor": "retailer",
        "transaction": {
          "standard": "X12",
          "transactionSet": "855",
          "businessUsage": "purchase_order_acknowledgment"
        },
        "occurrence": {
          "min": 1,
          "max": 1,
          "closure": {
            "kind": "fixed"
          }
        },
        "facts": [
          {
            "name": "purchaseOrderNumber",
            "type": "string",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "acknowledgmentCode",
            "type": "string",
            "cardinality": "one",
            "normalization": [],
            "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": "unitPrices",
            "type": "list",
            "elementType": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "financial"
          },
          {
            "name": "linesValid",
            "type": "boolean",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "hasBackorder",
            "type": "boolean",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "backorderedQuantity",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "purchaseOrderNumber",
              "acknowledgmentCode",
              "lineKeys",
              "quantities",
              "unitPrices",
              "linesValid",
              "hasBackorder",
              "backorderedQuantity"
            ]
          }
        ]
      },
      {
        "id": "advanceShipNotice",
        "fromActor": "supplier",
        "toActor": "retailer",
        "transaction": {
          "standard": "X12",
          "transactionSet": "856",
          "businessUsage": "advance_ship_notice"
        },
        "occurrence": {
          "min": 1,
          "max": 3,
          "closure": {
            "kind": "explicit"
          }
        },
        "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": 3,
          "closure": {
            "kind": "explicit"
          }
        },
        "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"
          },
          {
            "name": "invoiceNumber",
            "type": "string",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "purchaseOrderNumber",
              "shipmentId",
              "lineKeys",
              "quantities",
              "linesValid",
              "unitPrices",
              "lineTotal",
              "invoiceTotal",
              "currency",
              "invoiceNumber"
            ]
          }
        ]
      }
    ],
    "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": "P14D",
        "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": "P21D",
        "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": "P2D",
        "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"
            }
          },
          {
            "id": "sameItems",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "advanceShipNotice",
              "fact": "lineKeys",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "invoice",
              "fact": "lineKeys",
              "projection": "value"
            }
          },
          {
            "id": "sameQuantities",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "advanceShipNotice",
              "fact": "quantities",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "invoice",
              "fact": "quantities",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            },
            {
              "kind": "exactly",
              "scope": "per_from",
              "count": 1
            },
            {
              "kind": "exactly",
              "scope": "per_to",
              "count": 1
            }
          ],
          "unmatched": "fail"
        }
      }
    ],
    "assertions": [
      {
        "id": "acknowledgmentContainsChanges",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrderAcknowledgment",
          "fact": "acknowledgmentCode",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "string",
          "value": "AC"
        }
      },
      {
        "id": "acknowledgmentIdentifiesBackorder",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrderAcknowledgment",
          "fact": "hasBackorder",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "boolean",
          "value": true
        }
      },
      {
        "id": "purchaseOrderLinesValid",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "linesValid",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "boolean",
          "value": true
        }
      },
      {
        "id": "purchaseOrderAcknowledgmentLinesValid",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrderAcknowledgment",
          "fact": "linesValid",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "boolean",
          "value": true
        }
      },
      {
        "id": "advanceShipNoticeLinesValid",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "advanceShipNotice",
          "fact": "linesValid",
          "projection": "set"
        },
        "right": {
          "kind": "literal",
          "type": "set",
          "elementType": "boolean",
          "value": [
            true
          ]
        }
      },
      {
        "id": "invoiceLinesValid",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "linesValid",
          "projection": "set"
        },
        "right": {
          "kind": "literal",
          "type": "set",
          "elementType": "boolean",
          "value": [
            true
          ]
        }
      },
      {
        "id": "orderUsesUsd",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "currency",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "string",
          "value": "USD"
        }
      },
      {
        "id": "invoicesUseUsd",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "currency",
          "projection": "set"
        },
        "right": {
          "kind": "literal",
          "type": "set",
          "elementType": "string",
          "value": [
            "USD"
          ]
        }
      },
      {
        "id": "shipmentIdsUnique",
        "operator": "unique",
        "left": {
          "kind": "fact",
          "stepId": "advanceShipNotice",
          "fact": "shipmentId",
          "projection": "list"
        }
      },
      {
        "id": "invoiceNumbersUnique",
        "operator": "unique",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "invoiceNumber",
          "projection": "list"
        }
      },
      {
        "id": "purchaseOrderAcknowledgmentQuantitiesMatchOrder",
        "operator": "keyed_sum_equal",
        "left": {
          "kind": "keyed_facts",
          "stepId": "purchaseOrderAcknowledgment",
          "keyFact": "lineKeys",
          "fact": "quantities"
        },
        "right": {
          "kind": "keyed_facts",
          "stepId": "purchaseOrder",
          "keyFact": "lineKeys",
          "fact": "quantities"
        }
      },
      {
        "id": "advanceShipNoticeQuantitiesMatchOrder",
        "operator": "keyed_sum_equal",
        "left": {
          "kind": "keyed_facts",
          "stepId": "advanceShipNotice",
          "keyFact": "lineKeys",
          "fact": "quantities"
        },
        "right": {
          "kind": "keyed_facts",
          "stepId": "purchaseOrder",
          "keyFact": "lineKeys",
          "fact": "quantities"
        }
      },
      {
        "id": "invoiceQuantitiesMatchOrder",
        "operator": "keyed_sum_equal",
        "left": {
          "kind": "keyed_facts",
          "stepId": "invoice",
          "keyFact": "lineKeys",
          "fact": "quantities"
        },
        "right": {
          "kind": "keyed_facts",
          "stepId": "purchaseOrder",
          "keyFact": "lineKeys",
          "fact": "quantities"
        }
      },
      {
        "id": "purchaseOrderAcknowledgmentPricesMatchOrder",
        "operator": "keyed_equal",
        "left": {
          "kind": "keyed_facts",
          "stepId": "purchaseOrderAcknowledgment",
          "keyFact": "lineKeys",
          "fact": "unitPrices"
        },
        "right": {
          "kind": "keyed_facts",
          "stepId": "purchaseOrder",
          "keyFact": "lineKeys",
          "fact": "unitPrices"
        }
      },
      {
        "id": "invoicePricesMatchOrder",
        "operator": "keyed_equal",
        "left": {
          "kind": "keyed_facts",
          "stepId": "invoice",
          "keyFact": "lineKeys",
          "fact": "unitPrices"
        },
        "right": {
          "kind": "keyed_facts",
          "stepId": "purchaseOrder",
          "keyFact": "lineKeys",
          "fact": "unitPrices"
        }
      },
      {
        "id": "eachInvoiceTotalMatchesItsLines",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "invoiceTotal",
          "projection": "list"
        },
        "right": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "lineTotal",
          "projection": "list"
        }
      },
      {
        "id": "invoiceTotalsMatchOrder",
        "operator": "sum_equal",
        "left": {
          "kind": "fact",
          "stepId": "invoice",
          "fact": "invoiceTotal",
          "projection": "list"
        },
        "right": {
          "kind": "fact",
          "stepId": "purchaseOrder",
          "fact": "orderTotal",
          "projection": "value"
        }
      }
    ],
    "checkpoints": [],
    "branches": []
  }
}
