{
  "$schema": "https://www.modernedi.com/docs/scenarios/schemas/scenario-binding-v1.schema.json",
  "apiVersion": "modernedi.com/scenario-binding-authoring/v1",
  "kind": "ScenarioBinding",
  "metadata": {
    "id": "motorCarrierShipment",
    "name": "Motor-carrier shipment example"
  },
  "spec": {
    "regressionCases": [
      {
        "id": "accepted-delivered-invoiced",
        "name": "accepted delivered invoiced",
        "parameters": {},
        "observations": [
          {
            "stepId": "loadTender",
            "mappingCaseId": "tender-example",
            "observedAfterSeconds": 0
          },
          {
            "stepId": "tenderResponse",
            "mappingCaseId": "accept-example",
            "observedAfterSeconds": 60
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "pickup-example",
            "observedAfterSeconds": 86400
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "enroute-example",
            "observedAfterSeconds": 90000
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "delivery-example",
            "observedAfterSeconds": 100800
          },
          {
            "stepId": "freightInvoice",
            "mappingCaseId": "invoice-example",
            "observedAfterSeconds": 172800
          }
        ],
        "evaluatedAfterSeconds": 173000,
        "closeSteps": [
          "shipmentStatus"
        ],
        "expected": {
          "outcome": "PASSED",
          "checks": []
        }
      },
      {
        "id": "declined-tender-is-complete",
        "name": "declined tender is complete",
        "parameters": {},
        "observations": [
          {
            "stepId": "loadTender",
            "mappingCaseId": "tender-example",
            "observedAfterSeconds": 0
          },
          {
            "stepId": "tenderResponse",
            "mappingCaseId": "decline-example",
            "observedAfterSeconds": 60
          }
        ],
        "evaluatedAfterSeconds": 173000,
        "closeSteps": [],
        "expected": {
          "outcome": "PASSED",
          "checks": []
        }
      },
      {
        "id": "delivery-alone-does-not-close-collection",
        "name": "delivery alone does not close collection",
        "parameters": {},
        "observations": [
          {
            "stepId": "loadTender",
            "mappingCaseId": "tender-example",
            "observedAfterSeconds": 0
          },
          {
            "stepId": "tenderResponse",
            "mappingCaseId": "accept-example",
            "observedAfterSeconds": 60
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "pickup-example",
            "observedAfterSeconds": 86400
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "enroute-example",
            "observedAfterSeconds": 90000
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "delivery-example",
            "observedAfterSeconds": 100800
          },
          {
            "stepId": "freightInvoice",
            "mappingCaseId": "invoice-example",
            "observedAfterSeconds": 172800
          }
        ],
        "evaluatedAfterSeconds": 173000,
        "closeSteps": [],
        "expected": {
          "outcome": "PENDING",
          "checks": []
        }
      },
      {
        "id": "late-response",
        "name": "late response",
        "parameters": {},
        "observations": [
          {
            "stepId": "loadTender",
            "mappingCaseId": "tender-example",
            "observedAfterSeconds": 0
          },
          {
            "stepId": "tenderResponse",
            "mappingCaseId": "accept-example",
            "observedAfterSeconds": 7201
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "pickup-example",
            "observedAfterSeconds": 86400
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "enroute-example",
            "observedAfterSeconds": 90000
          },
          {
            "stepId": "shipmentStatus",
            "mappingCaseId": "delivery-example",
            "observedAfterSeconds": 100800
          },
          {
            "stepId": "freightInvoice",
            "mappingCaseId": "invoice-example",
            "observedAfterSeconds": 172800
          }
        ],
        "evaluatedAfterSeconds": 173000,
        "closeSteps": [
          "shipmentStatus"
        ],
        "expected": {
          "outcome": "FAILED",
          "checks": [
            {
              "id": "transition:responseForTender",
              "outcome": "FAILED",
              "code": "TRANSITION_WINDOW_EXPIRED"
            }
          ]
        }
      }
    ],
    "definition": {
      "namespace": "example",
      "key": "motor-carrier-shipment",
      "version": "1.0.0",
      "contentSha256": "a6c79523fed13f52cd49745b6ec1dae29d0fca8768181868730eabd7e2098a29"
    },
    "environment": "test",
    "actors": [
      {
        "actorId": "shipper",
        "endpoint": {
          "kind": "partner",
          "partnerId": 42
        }
      },
      {
        "actorId": "carrier",
        "endpoint": {
          "kind": "workspace"
        }
      }
    ],
    "steps": [
      {
        "stepId": "loadTender",
        "syntaxTree": {
          "x12Version": "004010",
          "transactionSet": "204"
        },
        "target": {
          "kind": "runtime-mapping",
          "runtimeMappingId": 101
        },
        "factSources": [
          {
            "fact": "loadId",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B2(04)"
            }
          },
          {
            "fact": "carrier",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B2(02)"
            }
          },
          {
            "fact": "agreedCharge",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "toNumber(ST->L3(05)) / 100"
            }
          },
          {
            "fact": "purpose",
            "source": {"kind": "x12-mapper-expression", "expression": "ST->B2A(01)"}
          },
          {
            "fact": "currency",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->L11[02 == \"RB\"](01)"
            }
          }
        ]
      },
      {
        "stepId": "tenderResponse",
        "syntaxTree": {
          "x12Version": "004010",
          "transactionSet": "990"
        },
        "target": {
          "kind": "runtime-mapping",
          "runtimeMappingId": 102
        },
        "factSources": [
          {
            "fact": "loadId",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B1(02)"
            }
          },
          {
            "fact": "carrier",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B1(01)"
            }
          },
          {
            "fact": "action",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B1(04)"
            }
          },
          {
            "fact": "actionSupported",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "trim(ST->B1(04)[0]) == \"A\" || trim(ST->B1(04)[0]) == \"R\""
            }
          }
        ]
      },
      {
        "stepId": "shipmentStatus",
        "syntaxTree": {
          "x12Version": "004010",
          "transactionSet": "214"
        },
        "target": {
          "kind": "runtime-mapping",
          "runtimeMappingId": 103
        },
        "factSources": [
          {
            "fact": "loadId",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B10(02)"
            }
          },
          {
            "fact": "carrier",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B10(03)"
            }
          },
          {
            "fact": "statusCode",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->LX->AT7(01)[0]"
            }
          },
          {
            "fact": "eventTimestamp",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "formatDate(ST->LX->AT7(05)[0], \"yyyy-MM-dd\") + \"T\" + substring(ST->LX->AT7(06)[0], 0, 2) + \":\" + substring(ST->LX->AT7(06)[0], 2, 4) + \":00Z\""
            }
          },
          {
            "fact": "eventDate",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "formatDate(ST->LX->AT7(05)[0], \"yyyy-MM-dd\")"
            }
          },
          {
            "fact": "timeCode",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->LX->AT7(07)[0]"
            }
          },
          {
            "fact": "oneUtcMinuteEvent",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "countOf(event in ST->LX->AT7) == 1 && substring(ST->LX->AT7(06)[0], 4) == \"\""
            }
          },
          {
            "fact": "pickupCount",
            "source": {"kind": "x12-mapper-expression", "expression": "countOf(event in ST->LX->AT7 : event(01) == \"AF\")"}
          },
          {
            "fact": "deliveryCount",
            "source": {"kind": "x12-mapper-expression", "expression": "countOf(event in ST->LX->AT7 : event(01) == \"D1\")"}
          }
        ]
      },
      {
        "stepId": "freightInvoice",
        "syntaxTree": {
          "x12Version": "004010",
          "transactionSet": "210"
        },
        "target": {
          "kind": "runtime-mapping",
          "runtimeMappingId": 104
        },
        "factSources": [
          {
            "fact": "loadId",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B3(03)"
            }
          },
          {
            "fact": "carrier",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->B3(11)"
            }
          },
          {
            "fact": "currency",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "ST->C3(01)"
            }
          },
          {
            "fact": "netCharge",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "toNumber(ST->B3(07)) / 100"
            }
          },
          {
            "fact": "summaryCharge",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "toNumber(ST->L3(05)) / 100"
            }
          },
          {
            "fact": "detailCharge",
            "source": {"kind": "x12-mapper-expression", "expression": "sumOf(line in ST->LX->L1 => toNumber(line(04))) / 100"}
          },
          {
            "fact": "chargeCount",
            "source": {"kind": "x12-mapper-expression", "expression": "countOf(line in ST->LX->L1)"}
          },
          {
            "fact": "deliveryDate",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "formatDate(ST->B3(09)[0], \"yyyy-MM-dd\")"
            }
          },
          {
            "fact": "invoiceDate",
            "source": {
              "kind": "x12-mapper-expression",
              "expression": "formatDate(ST->B3(06)[0], \"yyyy-MM-dd\")"
            }
          }
        ]
      }
    ]
  }
}
