{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://crapwatch.invalid/schemas/bypass_event.schema.json",
  "title": "Crapwatch AER itemised bypass-event row",
  "type": "object",
  "required": ["plant", "start", "end", "duration_value", "duration_unit", "duration_h", "volume_kL", "volume_raw", "volume_unit_raw", "volume_status", "raw_source_representation", "source_document", "source_sha256", "source_page", "source_row_occurrence_index", "exact_source_row_repeat_count", "physical_event_uniqueness", "extraction"],
  "properties": {
    "plant": {"type": "string", "minLength": 1},
    "start": {"type": "string", "minLength": 1},
    "end": {"type": "string", "minLength": 1},
    "duration_value": {"type": "number", "minimum": 0},
    "duration_unit": {"enum": ["h", "hours", "weeks"]},
    "duration_h": {"type": ["number", "null"], "minimum": 0},
    "volume_kL": {"type": ["number", "null"], "minimum": 0},
    "volume_raw": {"type": "string", "minLength": 1},
    "volume_unit_raw": {"type": ["string", "null"]},
    "volume_status": {"enum": ["OK", "UNKNOWN"]},
    "raw_source_representation": {"type": "string", "minLength": 1},
    "source_document": {"type": "string", "pattern": "\\.pdf$"},
    "source_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "source_page": {"type": "integer", "minimum": 1},
    "source_row_occurrence_index": {"type": "integer", "minimum": 1},
    "exact_source_row_repeat_count": {"type": "integer", "minimum": 1},
    "physical_event_uniqueness": {"enum": ["NO_EXACT_SOURCE_ROW_REPEAT", "UNRESOLVED_EXACT_REPEATED_SOURCE_ROW"]},
    "extraction": {"type": "string", "minLength": 1}
  },
  "allOf": [
    {"if": {"properties": {"volume_status": {"const": "OK"}}}, "then": {"properties": {"volume_kL": {"type": "number"}, "volume_unit_raw": {"enum": ["L", "kL", "ML"]}}}},
    {"if": {"properties": {"volume_status": {"const": "UNKNOWN"}}}, "then": {"properties": {"volume_kL": {"type": "null"}, "volume_unit_raw": {"type": "null"}}}}
  ],
  "additionalProperties": false
}
