{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openssom.org/schema/operational-context.json",
  "title": "SSOM Operational Context",
  "description": "A bounded period of operation that records refer to in order to be understood: a batch, a lot, a step of a procedure, a production order, a shift, an operating mode, a trip, a maintenance window, or a test run. RFC-0002 section 5.9.",
  "type": "object",
  "required": [
    "context_id",
    "context_type",
    "subject_refs",
    "valid_from",
    "provenance",
    "ssom_version"
  ],
  "properties": {
    "context_id": {
      "type": "string",
      "pattern": "^urn:ssom:operational-context:"
    },
    "ssom_version": {
      "type": "string"
    },
    "context_type": {
      "type": "string",
      "enum": [
        "batch",
        "lot",
        "procedural_element",
        "production_order",
        "campaign",
        "shift",
        "operating_mode",
        "trip",
        "maintenance_window",
        "test_run",
        "custom"
      ]
    },
    "custom_context_type": {
      "type": "string",
      "pattern": "^urn:ssom:ext:"
    },
    "display_name": {
      "type": "string"
    },
    "subject_refs": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string"
      }
    },
    "valid_from": {
      "type": "string",
      "format": "date-time"
    },
    "valid_to": {
      "type": "string",
      "format": "date-time"
    },
    "parent_context_ref": {
      "type": "string",
      "pattern": "^urn:ssom:operational-context:"
    },
    "context_identifiers": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "scheme",
          "value"
        ],
        "properties": {
          "scheme": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    },
    "related_refs": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "state_lineage": {
      "$ref": "common.json#/$defs/stateLineage"
    },
    "provenance": {
      "$ref": "common.json#/$defs/provenance"
    },
    "extensions": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "context_type": {
            "const": "custom"
          }
        },
        "required": [
          "context_type"
        ]
      },
      "then": {
        "required": [
          "custom_context_type"
        ]
      }
    }
  ],
  "additionalProperties": true
}
