{
  "$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": "motor-carrier-shipment",
    "version": "1.0.0"
  },
  "spec": {
    "actors": [
      {
        "id": "shipper"
      },
      {
        "id": "carrier"
      }
    ],
    "steps": [
      {
        "id": "loadTender",
        "fromActor": "shipper",
        "toActor": "carrier",
        "transaction": {
          "standard": "X12",
          "transactionSet": "204",
          "businessUsage": "loadTender"
        },
        "occurrence": {
          "min": 1,
          "max": 1,
          "closure": {
            "kind": "fixed"
          }
        },
        "facts": [
          {
            "name": "loadId",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "carrier",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "agreedCharge",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "financial"
          },
          {
            "name": "purpose",
            "type": "string",
            "cardinality": "one",
            "normalization": ["trim"],
            "sensitivity": "business"
          },
          {
            "name": "currency",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "loadId",
              "carrier",
              "agreedCharge",
              "purpose",
              "currency"
            ]
          }
        ]
      },
      {
        "id": "tenderResponse",
        "fromActor": "carrier",
        "toActor": "shipper",
        "transaction": {
          "standard": "X12",
          "transactionSet": "990",
          "businessUsage": "tenderResponse"
        },
        "occurrence": {
          "min": 1,
          "max": 1,
          "closure": {
            "kind": "fixed"
          }
        },
        "facts": [
          {
            "name": "loadId",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "carrier",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "action",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "actionSupported",
            "type": "boolean",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "loadId",
              "carrier",
              "action",
              "actionSupported"
            ]
          },
          {
            "id": "decision",
            "kind": "checkpoint",
            "checkpoint": "responseObserved"
          }
        ]
      },
      {
        "id": "shipmentStatus",
        "fromActor": "carrier",
        "toActor": "shipper",
        "transaction": {
          "standard": "X12",
          "transactionSet": "214",
          "businessUsage": "shipmentStatus"
        },
        "occurrence": {
          "min": 0,
          "max": 5,
          "closure": {
            "kind": "explicit"
          }
        },
        "facts": [
          {
            "name": "loadId",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "carrier",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "statusCode",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "eventTimestamp",
            "type": "timestamp",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "eventDate",
            "type": "date",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "timeCode",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "oneUtcMinuteEvent",
            "type": "boolean",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "pickupCount",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "deliveryCount",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "loadId",
              "carrier",
              "statusCode",
              "eventTimestamp",
              "eventDate",
              "timeCode",
              "oneUtcMinuteEvent",
              "pickupCount",
              "deliveryCount"
            ]
          }
        ]
      },
      {
        "id": "freightInvoice",
        "fromActor": "carrier",
        "toActor": "shipper",
        "transaction": {
          "standard": "X12",
          "transactionSet": "210",
          "businessUsage": "freightInvoice"
        },
        "occurrence": {
          "min": 1,
          "max": 1,
          "closure": {
            "kind": "fixed"
          }
        },
        "facts": [
          {
            "name": "loadId",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "carrier",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "currency",
            "type": "string",
            "cardinality": "one",
            "normalization": [
              "trim"
            ],
            "sensitivity": "business"
          },
          {
            "name": "netCharge",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "financial"
          },
          {
            "name": "summaryCharge",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "financial"
          },
          {
            "name": "detailCharge",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "financial"
          },
          {
            "name": "chargeCount",
            "type": "decimal",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "deliveryDate",
            "type": "date",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          },
          {
            "name": "invoiceDate",
            "type": "date",
            "cardinality": "one",
            "normalization": [],
            "sensitivity": "business"
          }
        ],
        "pipeline": [
          {
            "id": "exchange",
            "kind": "exchange"
          },
          {
            "id": "extract",
            "kind": "extract",
            "facts": [
              "loadId",
              "carrier",
              "currency",
              "netCharge",
              "summaryCharge",
              "detailCharge",
              "chargeCount",
              "deliveryDate",
              "invoiceDate"
            ]
          }
        ]
      }
    ],
    "transitions": [
      {
        "id": "responseForTender",
        "fromStep": "loadTender",
        "toStep": "tenderResponse",
        "relationship": "follows",
        "within": "PT2H",
        "correlations": [
          {
            "id": "sameLoad",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "loadTender",
              "fact": "loadId",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "tenderResponse",
              "fact": "loadId",
              "projection": "value"
            }
          },
          {
            "id": "sameCarrier",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "loadTender",
              "fact": "carrier",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "tenderResponse",
              "fact": "carrier",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            }
          ],
          "unmatched": "fail"
        }
      },
      {
        "id": "acceptedLoadStatus",
        "fromStep": "tenderResponse",
        "toStep": "shipmentStatus",
        "relationship": "follows",
        "within": "P7D",
        "correlations": [
          {
            "id": "sameLoad",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "tenderResponse",
              "fact": "loadId",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "shipmentStatus",
              "fact": "loadId",
              "projection": "value"
            }
          },
          {
            "id": "sameCarrier",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "tenderResponse",
              "fact": "carrier",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "shipmentStatus",
              "fact": "carrier",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            }
          ],
          "unmatched": "fail"
        }
      },
      {
        "id": "invoiceAfterStatus",
        "fromStep": "shipmentStatus",
        "toStep": "freightInvoice",
        "relationship": "follows",
        "within": "P7D",
        "correlations": [
          {
            "id": "sameLoad",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "shipmentStatus",
              "fact": "loadId",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "freightInvoice",
              "fact": "loadId",
              "projection": "value"
            }
          },
          {
            "id": "sameCarrier",
            "operator": "equal",
            "left": {
              "kind": "fact",
              "stepId": "shipmentStatus",
              "fact": "carrier",
              "projection": "value"
            },
            "right": {
              "kind": "fact",
              "stepId": "freightInvoice",
              "fact": "carrier",
              "projection": "value"
            }
          }
        ],
        "matching": {
          "strategy": "correlate",
          "quantifiers": [
            {
              "kind": "every",
              "scope": "from"
            },
            {
              "kind": "every",
              "scope": "to"
            }
          ],
          "unmatched": "fail"
        }
      }
    ],
    "assertions": [
      {
        "id": "originalTender",
        "operator": "equal",
        "left": {"kind": "fact", "stepId": "loadTender", "fact": "purpose", "projection": "value"},
        "right": {"kind": "literal", "type": "string", "value": "00"}
      },
      {
        "id": "onePickup",
        "operator": "sum_equal",
        "left": {"kind": "fact", "stepId": "shipmentStatus", "fact": "pickupCount", "projection": "list"},
        "right": {"kind": "literal", "type": "decimal", "value": 1}
      },
      {
        "id": "oneDelivery",
        "operator": "sum_equal",
        "left": {"kind": "fact", "stepId": "shipmentStatus", "fact": "deliveryCount", "projection": "list"},
        "right": {"kind": "literal", "type": "decimal", "value": 1}
      },
      {
        "id": "oneInvoiceCharge",
        "operator": "equal",
        "left": {"kind": "fact", "stepId": "freightInvoice", "fact": "chargeCount", "projection": "value"},
        "right": {"kind": "literal", "type": "decimal", "value": 1}
      },
      {
        "id": "invoiceDetailMatches",
        "operator": "equal",
        "left": {"kind": "fact", "stepId": "freightInvoice", "fact": "detailCharge", "projection": "value"},
        "right": {"kind": "fact", "stepId": "freightInvoice", "fact": "netCharge", "projection": "value"}
      },
      {
        "id": "responseActionSupported",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "tenderResponse",
          "fact": "actionSupported",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "boolean",
          "value": true
        }
      },
      {
        "id": "responseCarrierMatches",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "loadTender",
          "fact": "carrier",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "tenderResponse",
          "fact": "carrier",
          "projection": "value"
        }
      },
      {
        "id": "invoiceCarrierMatches",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "loadTender",
          "fact": "carrier",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "carrier",
          "projection": "value"
        }
      },
      {
        "id": "statusCodesSupported",
        "operator": "subset",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "statusCode",
          "projection": "set"
        },
        "right": {
          "kind": "literal",
          "type": "set",
          "elementType": "string",
          "value": [
            "AF",
            "X6",
            "D1"
          ]
        }
      },
      {
        "id": "pickupComesFirst",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "statusCode",
          "projection": "first"
        },
        "right": {
          "kind": "literal",
          "type": "string",
          "value": "AF"
        }
      },
      {
        "id": "deliveryComesLast",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "statusCode",
          "projection": "latest"
        },
        "right": {
          "kind": "literal",
          "type": "string",
          "value": "D1"
        }
      },
      {
        "id": "eventsAreChronological",
        "operator": "monotonic",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "eventTimestamp",
          "projection": "list"
        }
      },
      {
        "id": "eventTimesAreUnique",
        "operator": "unique",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "eventTimestamp",
          "projection": "list"
        }
      },
      {
        "id": "eventTimeProfile",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "oneUtcMinuteEvent",
          "projection": "set"
        },
        "right": {
          "kind": "literal",
          "type": "set",
          "elementType": "boolean",
          "value": [
            true
          ]
        }
      },
      {
        "id": "utcOnly",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "timeCode",
          "projection": "set"
        },
        "right": {
          "kind": "literal",
          "type": "set",
          "elementType": "string",
          "value": [
            "UT"
          ]
        }
      },
      {
        "id": "deliveryDateMatches",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "shipmentStatus",
          "fact": "eventDate",
          "projection": "latest"
        },
        "right": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "deliveryDate",
          "projection": "value"
        }
      },
      {
        "id": "invoiceDateAfterDelivery",
        "operator": "greater_than_or_equal",
        "left": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "invoiceDate",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "deliveryDate",
          "projection": "value"
        }
      },
      {
        "id": "tenderUsesUsd",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "loadTender",
          "fact": "currency",
          "projection": "value"
        },
        "right": {
          "kind": "literal",
          "type": "string",
          "value": "USD"
        }
      },
      {
        "id": "invoiceCurrencyMatches",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "loadTender",
          "fact": "currency",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "currency",
          "projection": "value"
        }
      },
      {
        "id": "invoiceMatchesAgreedCharge",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "loadTender",
          "fact": "agreedCharge",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "netCharge",
          "projection": "value"
        }
      },
      {
        "id": "invoiceSummaryMatches",
        "operator": "equal",
        "left": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "netCharge",
          "projection": "value"
        },
        "right": {
          "kind": "fact",
          "stepId": "freightInvoice",
          "fact": "summaryCharge",
          "projection": "value"
        }
      }
    ],
    "parameters": [],
    "checkpoints": [
      {
        "id": "responseObserved"
      }
    ],
    "branches": [
      {
        "id": "acceptedOrDeclined",
        "mode": "at_most_one",
        "checkpoint": "responseObserved",
        "alternatives": [
          {
            "id": "accepted",
            "kind": "when",
            "transitionId": "acceptedLoadStatus",
            "conditions": [
              {
                "id": "accept",
                "operator": "equal",
                "left": {
                  "kind": "fact",
                  "stepId": "tenderResponse",
                  "fact": "action",
                  "projection": "value"
                },
                "right": {
                  "kind": "literal",
                  "type": "string",
                  "value": "A"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}
