{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://crapwatch.invalid/schemas/parameter.schema.json",
  "title": "Crapwatch AER compliance parameter row",
  "type": "object",
  "required": ["plant", "chapter", "parameter", "parameter_raw", "parameter_status", "units", "units_raw", "units_status", "source_document", "source_sha256", "source_page", "source_column", "source_table", "source_section", "source_header_raw", "source_row_provenance", "compliance_scope", "compliance_scope_raw", "compliance_scope_status"],
  "properties": {
    "plant": {"type": "string", "minLength": 1},
    "chapter": {"type": ["integer", "null"], "minimum": 1},
    "parameter": {"enum": ["Ammonia", "BOD5", "Chlorine", "Total nitrogen", "Oil and grease", "pH", "Total phosphorus", "E. coli", "Enterococci", "Total suspended solids"]},
    "parameter_raw": {"type": "string", "minLength": 1},
    "parameter_status": {"enum": ["OK", "CANONICALIZED_ALIAS"]},
    "units": {"type": ["string", "null"]},
    "units_raw": {"type": ["string", "null"]},
    "units_status": {"enum": ["OK", "SOURCE_BLANK", "ABSENT_FROM_TABLE"]},
    "units_source_page": {"type": ["integer", "null"], "minimum": 1},
    "source_document": {"type": "string", "pattern": "\\.pdf$"},
    "source_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "source_page": {"type": "integer", "minimum": 1},
    "source_column": {"type": "integer", "minimum": 1},
    "source_table": {"type": "string", "minLength": 1},
    "source_section": {"const": "Discharge compliance with permit limits"},
    "source_header_raw": {"type": "string", "minLength": 1},
    "source_row_provenance": {"type": "string", "minLength": 1},
    "compliance_scope": {"enum": ["TREATED_EFFLUENT", "REUSE", "UNKNOWN"]},
    "compliance_scope_raw": {"type": ["string", "null"]},
    "compliance_scope_status": {"type": "string", "minLength": 1}
  },
  "patternProperties": {
    "^(limit_(max|min|p50|p90)|samples_(required|analysed)|result_(max|min|p50|p90)|pct_compliance_(max|p50|p90|ph))$": {"type": ["number", "null"]},
    "^(limit_(max|min|p50|p90)|samples_(required|analysed)|result_(max|min|p50|p90)|pct_compliance_(max|p50|p90|ph))_raw$": {"type": ["string", "null"]},
    "^(limit_(max|min|p50|p90)|samples_(required|analysed)|result_(max|min|p50|p90)|pct_compliance_(max|p50|p90|ph))_status$": {"enum": ["OK", "OK_ANNOTATED", "SOURCE_BLANK", "SOURCE_SINGLE_DASH", "SOURCE_DOUBLE_DASH", "SOURCE_EM_DASH", "SOURCE_NA", "ABSENT_FROM_TABLE", "UNPARSED"]},
    "^(limit_(max|min|p50|p90)|samples_(required|analysed)|result_(max|min|p50|p90)|pct_compliance_(max|p50|p90|ph))_source_page$": {"type": ["integer", "null"], "minimum": 1}
  },
  "additionalProperties": false
}
