{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://crapwatch.example/schemas/flow_pathway.schema.json",
  "title": "Crapwatch source-stated flow monitoring pathway CSV row",
  "type": "object",
  "additionalProperties": false,
  "required": ["plant", "reporting_year", "flow_stream", "semantic_role", "spatial_source_state", "authoritative_outfall_geometry", "location_name_raw", "location_status", "coordinates_raw", "coordinates_status", "easting", "northing", "crs", "measurement_method", "measurement_method_raw", "last_calibration_validation_raw", "calibration_validation_status", "source_document", "source_sha256", "source_page", "source_table", "source_row_location_raw", "source_row_coordinates_raw", "source_row_method_raw", "source_row_calibration_raw", "extraction_status"],
  "properties": {
    "plant": {"type": "string", "minLength": 1},
    "reporting_year": {"const": "2024-25"},
    "flow_stream": {"enum": ["INFLUENT", "EFFLUENT_DISCHARGE_TO_WATERS", "REUSE", "BYPASS", "EMERGENCY_OUTFALL", "OTHER", "UNKNOWN"]},
    "semantic_role": {"const": "FLOW_MONITORING_SUMMARY_LOCATION"},
    "spatial_source_state": {"enum": ["SOURCE_STATED_TABULAR_COORDINATE", "NOT_STATED_OR_NOT_APPLICABLE"]},
    "authoritative_outfall_geometry": {"const": "NOT_ESTABLISHED"},
    "location_name_raw": {"type": "string"},
    "location_status": {"enum": ["PRESENT", "SOURCE_BLANK", "NOT_APPLICABLE_SOURCE"]},
    "coordinates_raw": {"type": "string"},
    "coordinates_status": {"enum": ["PRESENT", "SOURCE_BLANK", "NOT_APPLICABLE_SOURCE", "UNPARSED"]},
    "easting": {"type": ["integer", "null"]},
    "northing": {"type": ["integer", "null"]},
    "crs": {"const": "NOT_STATED"},
    "measurement_method": {"enum": ["METERED", "CALCULATED", "ESTIMATED", "MIXED", "NOT_STATED", "NOT_APPLICABLE"]},
    "measurement_method_raw": {"type": "string"},
    "last_calibration_validation_raw": {"type": "string"},
    "calibration_validation_status": {"enum": ["PRESENT", "SOURCE_BLANK", "NOT_APPLICABLE_SOURCE"]},
    "source_document": {"type": "string", "pattern": "\\.pdf$"},
    "source_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "source_page": {"type": "integer", "minimum": 1},
    "source_table": {"const": "Flow monitoring summary (Table x-A)"},
    "source_row_location_raw": {"type": "string", "minLength": 1},
    "source_row_coordinates_raw": {"type": "string", "minLength": 1},
    "source_row_method_raw": {"type": "string", "minLength": 1},
    "source_row_calibration_raw": {"type": "string", "minLength": 1},
    "extraction_status": {"const": "SOURCE_TABLE_SEMANTICS_PRESERVED"}
  },
  "allOf": [
    {"if": {"properties": {"coordinates_status": {"const": "PRESENT"}}}, "then": {"properties": {"easting": {"type": "integer", "minimum": 0}, "northing": {"type": "integer", "minimum": 0}, "spatial_source_state": {"const": "SOURCE_STATED_TABULAR_COORDINATE"}}}},
    {"if": {"properties": {"coordinates_status": {"enum": ["SOURCE_BLANK", "NOT_APPLICABLE_SOURCE", "UNPARSED"]}}}, "then": {"properties": {"easting": {"type": "null"}, "northing": {"type": "null"}}}}
  ]
}
