{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://civicdataforge.pages.dev/schemas/property-operating-record-v1.schema.json",
  "title": "CivicDataForge Property Operating Record v1",
  "description": "A building- or parcel-scoped property record whose facts retain value, presence, evidence state, source, method and limitations. It is not an appraisal, tax return, title report, listing feed or investment recommendation.",
  "type": "object",
  "additionalProperties": false,
  "required": ["building_address", "state", "observed_at", "facts", "derived_metrics", "operations_receipt_hash"],
  "properties": {
    "building_address": {"type": ["string", "null"]},
    "parcel_id": {"type": ["string", "null"], "minLength": 1, "maxLength": 40},
    "state": {"enum": ["CHECKED", "NO_PUBLISHED_PARCEL_MATCH", "ADDRESS_REVIEW", "UNAVAILABLE", "NOT_CHECKED", "NOT_COVERED", "BOUNDED"]},
    "observed_at": {"type": ["string", "null"], "format": "date-time"},
    "facts": {"type": "object", "additionalProperties": {"$ref": "#/$defs/fact"}},
    "derived_metrics": {"type": "object", "additionalProperties": {"$ref": "#/$defs/fact"}},
    "resources": {
      "type": "object", "additionalProperties": false,
      "required": ["state", "views", "official_contacts", "boundary"],
      "properties": {
        "state": {"enum": ["AVAILABLE", "COORDINATES_UNAVAILABLE"]},
        "views": {"type": "array", "items": {"$ref": "#/$defs/view"}, "maxItems": 2},
        "official_contacts": {"type": "array", "items": {"$ref": "#/$defs/contact"}, "maxItems": 8},
        "boundary": {"type": "string", "minLength": 1, "maxLength": 500}
      }
    },
    "composition_context": {
      "type": "object", "additionalProperties": false,
      "required": ["currency", "period_start", "period_end", "period_basis", "selected_market_value_path"],
      "properties": {
        "currency": {"type": ["string", "null"], "pattern": "^[A-Z]{3}$"},
        "period_start": {"type": ["string", "null"], "format": "date-time"},
        "period_end": {"type": ["string", "null"], "format": "date-time"},
        "period_basis": {"type": ["string", "null"], "enum": ["ANNUAL", "TRAILING_TWELVE_MONTHS", null]},
        "selected_market_value_path": {"type": ["string", "null"]}
      }
    },
    "input_state": {"enum": ["NO_PRIVATE_INPUT", "COMPOSED_EPHEMERAL"]},
    "private_input_receipt_hash": {"type": ["string", "null"], "pattern": "^sha256:[0-9a-f]{64}$"},
    "operations_receipt_hash": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"}
  },
  "$defs": {
    "view": {
      "type": "object", "additionalProperties": false,
      "required": ["kind", "label", "url", "evidence_state", "method_ref", "input_paths", "boundary"],
      "properties": {
        "kind": {"enum": ["SATELLITE_MAP", "NEARBY_STREET_VIEW"]},
        "label": {"type": "string", "minLength": 1, "maxLength": 100},
        "url": {"type": "string", "format": "uri", "pattern": "^https://www\\.google\\.com/maps/"},
        "evidence_state": {"const": "DERIVED"},
        "method_ref": {"type": "string", "minLength": 1},
        "input_paths": {"type": "array", "items": {"enum": ["facts.latitude", "facts.longitude"]}, "minItems": 2, "maxItems": 2, "uniqueItems": true},
        "boundary": {"type": "string", "minLength": 1, "maxLength": 500}
      }
    },
    "contact": {
      "type": "object", "additionalProperties": false,
      "required": ["role", "label", "url", "phone", "email", "reviewed_at"],
      "properties": {
        "role": {"type": "string", "pattern": "^[A-Z0-9_]+$"},
        "label": {"type": "string", "minLength": 1, "maxLength": 160},
        "url": {"type": "string", "format": "uri", "pattern": "^https://"},
        "phone": {"type": ["string", "null"], "maxLength": 40},
        "email": {"type": ["string", "null"], "format": "email", "maxLength": 254},
        "reviewed_at": {"type": "string", "format": "date-time"}
      }
    },
    "fact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "presence", "evidence_state", "source_ref", "method_ref", "note"],
      "properties": {
        "value": {},
        "presence": {"enum": ["absent", "null", "empty", "value"]},
        "evidence_state": {"enum": ["OBSERVED", "OBSERVED_CALLER_ASSERTED", "OBSERVED_PRIVATE", "DERIVED", "DERIVED_PRIVATE", "CONFLICTED", "UNKNOWN"]},
        "source_ref": {"type": ["string", "null"]},
        "method_ref": {"type": "string"},
        "note": {"type": ["string", "null"]},
        "input_paths": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}
      }
    }
  }
}
