{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.invalid/berthops/scenario.schema.json",
  "title": "BerthOps fictional disruption scenario",
  "type": "object",
  "required": ["schemaVersion", "scenarioId", "title", "simulationTime", "event", "ports", "vessels"],
  "properties": {
    "schemaVersion": {"const": 1},
    "scenarioId": {"type": "string", "minLength": 1},
    "title": {"type": "string", "minLength": 1},
    "simulationTime": {"type": "string", "format": "date-time"},
    "event": {
      "type": "object",
      "required": ["area", "windowStart", "windowEnd", "severity", "confidence", "description"],
      "properties": {
        "area": {"type": "string", "minLength": 1},
        "windowStart": {"type": "string", "format": "date-time"},
        "windowEnd": {"type": "string", "format": "date-time"},
        "severity": {"type": "string", "minLength": 1},
        "confidence": {"type": "number", "minimum": 0, "maximum": 1},
        "description": {"type": "string", "minLength": 1}
      }
    },
    "ports": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/port"}},
    "vessels": {"type": "array", "minItems": 2, "items": {"$ref": "#/$defs/vessel"}}
  },
  "$defs": {
    "port": {
      "type": "object",
      "required": ["id", "name", "congestionHours", "berthSlots", "pilotTugAvailable", "windowStart", "windowEnd"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "name": {"type": "string", "minLength": 1},
        "congestionHours": {"type": "number", "minimum": 0},
        "berthSlots": {"type": "integer", "minimum": 1},
        "pilotTugAvailable": {"type": "boolean"},
        "windowStart": {"type": "string", "format": "date-time"},
        "windowEnd": {"type": "string", "format": "date-time"}
      }
    },
    "vessel": {
      "type": "object",
      "required": ["id", "name", "service", "nextPort", "affected", "eta", "fuelTonnes", "draftMetres", "maxDraftMetres", "crewRestHours", "maintenanceHold", "cargo", "options"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "name": {"type": "string", "minLength": 1},
        "service": {"type": "string", "minLength": 1},
        "nextPort": {"type": "string", "minLength": 1},
        "affected": {"type": "boolean"},
        "eta": {"type": "string", "format": "date-time"},
        "fuelTonnes": {"type": "number", "minimum": 0},
        "draftMetres": {"type": "number", "minimum": 0},
        "maxDraftMetres": {"type": "number", "minimum": 0},
        "crewRestHours": {"type": "number", "minimum": 0},
        "maintenanceHold": {"type": "boolean"},
        "cargo": {"$ref": "#/$defs/cargo"},
        "options": {"type": "array", "minItems": 3, "items": {"$ref": "#/$defs/option"}, "allOf": [{"contains": {"type": "object", "properties": {"id": {"const": "direct"}}, "required": ["id"]}}, {"contains": {"type": "object", "properties": {"id": {"const": "south"}}, "required": ["id"]}}, {"contains": {"type": "object", "properties": {"id": {"const": "hold"}}, "required": ["id"]}}]}
      }
    },
    "cargo": {
      "type": "object",
      "required": ["reefer", "dangerousGoods", "keyCustomers", "connectionHours", "commitment"],
      "properties": {
        "reefer": {"type": "number", "minimum": 0},
        "dangerousGoods": {"type": "number", "minimum": 0},
        "keyCustomers": {"type": "array", "items": {"type": "string"}},
        "connectionHours": {"type": "number", "minimum": 0},
        "commitment": {"type": "string"}
      }
    },
    "option": {
      "type": "object",
      "required": ["id", "label", "distanceNm", "speedKnots", "fuelTonnes", "weatherRisk", "delayHours", "extraCostUsd", "emissionsTonnes"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "label": {"type": "string", "minLength": 1},
        "distanceNm": {"type": "number", "minimum": 0},
        "speedKnots": {"type": "number", "exclusiveMinimum": 0},
        "fuelTonnes": {"type": "number", "minimum": 0},
        "weatherRisk": {"type": "number", "minimum": 0, "maximum": 10},
        "delayHours": {"type": "number", "minimum": 0},
        "extraCostUsd": {"type": "number", "minimum": 0},
        "emissionsTonnes": {"type": "number", "minimum": 0},
        "veto": {"type": "string"}
      }
    }
  }
}
