{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://crapwatch.example/schemas/plant_permit.schema.json",
  "title": "Plant environmental permit/EPN identifier association",
  "type": "object",
  "additionalProperties": false,
  "required": ["plant", "identifier_order", "identifier_type", "identifier_value",
    "identifier_prefix", "identifier_qualifier", "issue_date_raw",
    "date_association_status", "raw_identifier_line", "raw_value_cell",
    "raw_date_cell", "source_document", "source_sha256", "source_page",
    "source_section", "extraction_status", "ambiguity_note"],
  "properties": {
    "plant": {"type": "string", "minLength": 1},
    "identifier_order": {"type": "integer", "minimum": 1},
    "identifier_type": {"enum": ["EPN", "PCE", "PERMIT_CONDITIONS_ENVIRONMENTAL", "UNPARSED_IDENTIFIER"]},
    "identifier_value": {"type": "string", "minLength": 1},
    "identifier_prefix": {"type": "string", "minLength": 1},
    "identifier_qualifier": {"type": ["string", "null"]},
    "issue_date_raw": {"type": ["string", "null"]},
    "date_association_status": {"enum": ["ORDERED_ONE_TO_ONE", "AMBIGUOUS_SHARED_DATE", "COUNT_MISMATCH_UNRESOLVED"]},
    "raw_identifier_line": {"type": "string", "minLength": 1},
    "raw_value_cell": {"type": "string", "minLength": 1},
    "raw_date_cell": {"type": "string", "minLength": 1},
    "source_document": {"type": "string", "pattern": "\\.pdf$"},
    "source_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "source_page": {"const": 1},
    "source_section": {"const": "Activity and report details — EPN row"},
    "extraction_status": {"enum": ["OK", "UNPARSED"]},
    "ambiguity_note": {"type": ["string", "null"]}
  }
}
