{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cleanedweb.com/schemas/property-profile-v2.json",
  "title": "CleanedWeb global property profile",
  "description": "One maintained property profile with grouped marketplace listings, official records when available, historical observations, area context, and provenance across markets.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "property_entity_id",
    "identifiers",
    "location",
    "property",
    "availability",
    "sources",
    "history",
    "context",
    "provenance"
  ],
  "properties": {
    "schema_version": {"const": "property-profile-v2"},
    "property_entity_id": {"type": "string", "minLength": 1, "maxLength": 300},
    "identifiers": {"$ref": "#/$defs/identifiers"},
    "location": {"$ref": "#/$defs/location"},
    "property": {"$ref": "#/$defs/property"},
    "availability": {"$ref": "#/$defs/availability"},
    "sources": {"type": "array", "items": {"$ref": "#/$defs/sourceGroup"}},
    "history": {"$ref": "#/$defs/history"},
    "context": {"$ref": "#/$defs/context"},
    "provenance": {"$ref": "#/$defs/provenance"}
  },
  "$defs": {
    "dateTimeOrNull": {"type": ["string", "null"], "format": "date-time"},
    "dateOrNull": {"type": ["string", "null"], "format": "date"},
    "stringList": {
      "type": "array",
      "items": {"type": "string", "minLength": 1},
      "uniqueItems": true
    },
    "linkEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["method", "confidence", "evidence_refs"],
      "properties": {
        "method": {"type": "string", "minLength": 1},
        "confidence": {"type": "number", "minimum": 0, "maximum": 1},
        "matcher_version": {"type": "string", "minLength": 1},
        "evidence_refs": {"$ref": "#/$defs/stringList"}
      }
    },
    "parcelIdentifier": {
      "type": "object",
      "additionalProperties": false,
      "required": ["parcel_id", "link"],
      "properties": {
        "country_code": {"type": "string", "pattern": "^[A-Z]{2}$"},
        "jurisdiction": {"type": "string", "minLength": 1},
        "state": {"type": "string", "pattern": "^[A-Z]{2}$"},
        "county_code": {"type": "string", "minLength": 1},
        "county_fips": {"type": "string", "pattern": "^[0-9]{5}$"},
        "parcel_id": {"type": "string", "minLength": 1},
        "assessor_parcel_id": {"type": "string", "minLength": 1},
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "source_attributes": {"type": "object", "additionalProperties": true},
        "link": {"$ref": "#/$defs/linkEvidence"}
      }
    },
    "identifiers": {
      "type": "object",
      "additionalProperties": false,
      "required": ["parcels"],
      "properties": {
        "parcels": {
          "type": "array",
          "items": {"$ref": "#/$defs/parcelIdentifier"}
        }
      }
    },
    "location": {
      "type": "object",
      "additionalProperties": false,
      "required": ["precision"],
      "properties": {
        "address": {"type": "string", "minLength": 1},
        "street": {"type": "string", "minLength": 1},
        "city": {"type": "string", "minLength": 1},
        "region": {"type": "string", "minLength": 1},
        "district": {"type": "string", "minLength": 1},
        "neighbourhood": {"type": "string", "minLength": 1},
        "postal_code": {"type": "string", "minLength": 1},
        "latitude": {"type": "number", "minimum": -90, "maximum": 90},
        "longitude": {"type": "number", "minimum": -180, "maximum": 180},
        "precision": {"type": "string", "minLength": 1}
      }
    },
    "property": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "category": {"enum": ["apartment", "house", "land", "commercial", "parking", "building", "room", "other"]},
        "type": {"type": "string", "minLength": 1},
        "building_type": {"type": "string", "minLength": 1},
        "floor_area": {"type": "number", "minimum": 0},
        "land_area": {"type": "number", "minimum": 0},
        "building_count": {"type": "integer", "minimum": 0},
        "floor": {"type": "number"},
        "rooms": {"type": "number", "minimum": 0},
        "bedrooms": {"type": "number", "minimum": 0},
        "bathrooms": {"type": "number", "minimum": 0},
        "year_built": {"type": "integer", "minimum": 1000, "maximum": 3000},
        "condition": {"type": "string", "minLength": 1},
        "energy_class": {"type": "string", "minLength": 1},
        "building_structure": {"type": "string", "minLength": 1},
        "construction_materials": {"$ref": "#/$defs/stringList"},
        "construction_status": {"type": "string", "minLength": 1},
        "heating": {"type": "string", "minLength": 1},
        "elevator": {"type": "boolean"},
        "parking": {"type": "string", "minLength": 1},
        "orientation": {"type": "string", "minLength": 1},
        "window_type": {"type": "string", "minLength": 1},
        "amenities": {"$ref": "#/$defs/stringList"},
        "features": {"$ref": "#/$defs/stringList"}
      }
    },
    "availability": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "active_deal_types", "determined_at", "method", "coverage_receipt_ids", "limitations"],
      "properties": {
        "status": {"enum": ["active", "off_market", "unknown"]},
        "active_deal_types": {
          "type": "array",
          "items": {"enum": ["Buy", "Rent"]},
          "uniqueItems": true
        },
        "determined_at": {"$ref": "#/$defs/dateTimeOrNull"},
        "method": {"type": "string", "minLength": 1},
        "coverage_receipt_ids": {"$ref": "#/$defs/stringList"},
        "limitations": {"$ref": "#/$defs/stringList"}
      }
    },
    "sourceGroup": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_id", "listings"],
      "properties": {
        "source_id": {"type": "string", "minLength": 1},
        "listings": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/sourceListing"}}
      }
    },
    "sourceListing": {
      "type": "object",
      "additionalProperties": false,
      "required": ["listing_id", "status", "is_current"],
      "properties": {
        "listing_id": {"type": "string", "minLength": 1},
        "source_property_id": {"type": "string", "minLength": 1},
        "links": {"$ref": "#/$defs/listingLinks"},
        "deal_type": {"enum": ["Buy", "Rent", "Off-market"]},
        "status": {"type": "string", "minLength": 1},
        "is_current": {"type": "boolean"},
        "first_observed_at": {"type": "string", "format": "date-time"},
        "observed_at": {"type": "string", "format": "date-time"},
        "pricing": {"$ref": "#/$defs/listingPricing"},
        "unit": {"$ref": "#/$defs/property"},
        "content": {"$ref": "#/$defs/listingContent"},
        "availability": {"$ref": "#/$defs/listingAvailability"},
        "advertiser": {"$ref": "#/$defs/listingAdvertiser"},
        "metrics": {"$ref": "#/$defs/listingMetrics"},
        "flags": {"$ref": "#/$defs/listingFlags"},
        "attribution": {"$ref": "#/$defs/listingAttribution"},
        "source_attributes": {"type": "object", "additionalProperties": true}
      }
    },
    "listingLinks": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "advertisement": {"type": "string", "format": "uri"},
        "canonical": {"type": "string", "format": "uri"},
        "contact": {"type": "string", "format": "uri"}
      }
    },
    "money": {
      "type": "object",
      "additionalProperties": false,
      "required": ["amount"],
      "properties": {
        "amount": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "pattern": "^[A-Z]{3}$"}
      }
    },
    "listingFee": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {"type": "string", "minLength": 1},
        "amount": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
        "frequency": {"type": "string", "minLength": 1},
        "description": {"type": "string", "minLength": 1}
      }
    },
    "listingPricing": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "asking_price": {"$ref": "#/$defs/money"},
        "maximum_asking_price": {"$ref": "#/$defs/money"},
        "previous_asking_price": {"$ref": "#/$defs/money"},
        "discount": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "amount": {"type": "number", "minimum": 0},
            "percentage": {"type": "number", "minimum": 0}
          }
        },
        "price_text": {"type": "string", "minLength": 1},
        "price_type": {"type": "string", "minLength": 1},
        "quality": {"enum": ["known", "hidden", "placeholder", "missing"]},
        "fees": {"type": "array", "items": {"$ref": "#/$defs/listingFee"}}
      }
    },
    "listingContent": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "title": {"type": "string", "minLength": 1},
        "description": {"type": "string", "minLength": 1},
        "tags": {"$ref": "#/$defs/stringList"},
        "disclaimers": {"$ref": "#/$defs/stringList"}
      }
    },
    "openHouse": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "starts_at": {"type": "string", "format": "date-time"},
        "ends_at": {"type": "string", "format": "date-time"},
        "description": {"type": "string", "minLength": 1}
      }
    },
    "listingAvailability": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "posted_at": {"type": "string", "format": "date-time"},
        "available_at": {"type": "string", "format": "date-time"},
        "coming_soon_at": {"type": "string", "format": "date-time"},
        "tour_available": {"type": "boolean"},
        "open_houses": {"type": "array", "items": {"$ref": "#/$defs/openHouse"}}
      }
    },
    "listingAdvertiser": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {"type": "string", "minLength": 1},
        "agency": {"$ref": "#/$defs/agency"},
        "agent": {"$ref": "#/$defs/agent"},
        "developer": {"$ref": "#/$defs/agency"},
        "contact": {"$ref": "#/$defs/contact"}
      }
    },
    "listingMetrics": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "days_on_market": {"type": "number", "minimum": 0},
        "views": {"type": "number", "minimum": 0},
        "saves": {"type": "number", "minimum": 0}
      }
    },
    "listingFlags": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "featured": {"type": "boolean"},
        "showcase": {"type": "boolean"},
        "has_video": {"type": "boolean"},
        "has_3d_tour": {"type": "boolean"},
        "foreclosure": {"type": "boolean"}
      }
    },
    "listingAttribution": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "brokerage": {"type": "string", "minLength": 1},
        "mls": {"type": "string", "minLength": 1},
        "display_text": {"type": "string", "minLength": 1}
      }
    },
    "agency": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "name": {"type": "string", "minLength": 1},
        "url": {"type": "string", "format": "uri"}
      }
    },
    "agent": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "job_title": {"type": "string", "minLength": 1},
        "profile_url": {"type": "string", "format": "uri"}
      }
    },
    "contact": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "phones": {"$ref": "#/$defs/stringList"},
        "emails": {
          "type": "array",
          "items": {"type": "string", "format": "email"},
          "uniqueItems": true
        },
        "websites": {
          "type": "array",
          "items": {"type": "string", "format": "uri"},
          "uniqueItems": true
        },
        "contact_form_url": {"type": "string", "format": "uri"}
      }
    },
    "listingEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["event_id", "event_type", "source_id", "source_record_id", "source_kind", "authority"],
      "properties": {
        "event_id": {"type": "string", "minLength": 1},
        "event_type": {"enum": ["listed", "price_changed", "pending", "sold", "rented", "off_market", "relisted", "other"]},
        "deal_type": {"enum": ["Buy", "Rent"]},
        "effective_at": {"$ref": "#/$defs/dateOrNull"},
        "observed_at": {"$ref": "#/$defs/dateTimeOrNull"},
        "price": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "source_kind": {"const": "listing_source"},
        "authority": {"const": "advertised"},
        "source_event": {"type": "string", "minLength": 1},
        "vintage": {"type": "string", "minLength": 1},
        "limitation": {"type": "string", "minLength": 1}
      }
    },
    "recordedTransfer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["event_id", "event_type", "source_id", "source_record_id", "source_kind", "authority"],
      "properties": {
        "event_id": {"type": "string", "minLength": 1},
        "event_type": {"const": "recorded_transfer"},
        "effective_at": {"$ref": "#/$defs/dateOrNull"},
        "observed_at": {"$ref": "#/$defs/dateTimeOrNull"},
        "amount": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
        "qualification_code": {"type": "string", "minLength": 1},
        "instrument_number": {"type": "string", "minLength": 1},
        "official_record_book": {"type": "string", "minLength": 1},
        "official_record_page": {"type": "string", "minLength": 1},
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "source_kind": {"const": "public_record_source"},
        "authority": {"const": "recorded"},
        "vintage": {"type": "string", "minLength": 1},
        "limitation": {"type": "string", "minLength": 1}
      }
    },
    "assessment": {
      "type": "object",
      "additionalProperties": false,
      "required": ["event_id", "event_type", "source_id", "source_record_id", "source_kind", "authority"],
      "properties": {
        "event_id": {"type": "string", "minLength": 1},
        "event_type": {"const": "tax_assessment"},
        "effective_at": {"$ref": "#/$defs/dateOrNull"},
        "observed_at": {"$ref": "#/$defs/dateTimeOrNull"},
        "assessed_value": {"type": "number", "minimum": 0},
        "just_value": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "source_kind": {"const": "public_record_source"},
        "authority": {"const": "assessed"},
        "vintage": {"type": "string", "minLength": 1},
        "limitation": {"type": "string", "minLength": 1}
      }
    },
    "valuation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["event_id", "event_type", "valuation_type", "amount", "source_id", "source_record_id", "source_kind", "authority"],
      "properties": {
        "event_id": {"type": "string", "minLength": 1},
        "event_type": {"const": "valuation"},
        "valuation_type": {"type": "string", "minLength": 1},
        "effective_at": {"$ref": "#/$defs/dateOrNull"},
        "observed_at": {"$ref": "#/$defs/dateTimeOrNull"},
        "amount": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "source_kind": {"const": "listing_source"},
        "authority": {"const": "estimated"},
        "vintage": {"type": "string", "minLength": 1},
        "limitation": {"type": "string", "minLength": 1}
      }
    },
    "ownershipEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["event_id", "event_type", "ownership_type", "source_id", "source_record_id", "source_kind", "authority"],
      "properties": {
        "event_id": {"type": "string", "minLength": 1},
        "event_type": {"const": "ownership_observed"},
        "effective_at": {"$ref": "#/$defs/dateOrNull"},
        "observed_at": {"$ref": "#/$defs/dateTimeOrNull"},
        "owner_party_ref": {"type": "string", "minLength": 1},
        "ownership_type": {"type": "string", "minLength": 1},
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "source_kind": {"const": "public_record_source"},
        "authority": {"const": "recorded_owner_observation"},
        "vintage": {"type": "string", "minLength": 1},
        "limitation": {"type": "string", "minLength": 1}
      }
    },
    "taxEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["event_id", "event_type", "source_id", "source_record_id", "source_kind", "authority"],
      "properties": {
        "event_id": {"type": "string", "minLength": 1},
        "event_type": {"const": "property_tax"},
        "effective_at": {"$ref": "#/$defs/dateOrNull"},
        "observed_at": {"$ref": "#/$defs/dateTimeOrNull"},
        "amount": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "source_kind": {"enum": ["public_record_source", "listing_source"]},
        "authority": {"type": "string", "minLength": 1},
        "vintage": {"type": "string", "minLength": 1},
        "limitation": {"type": "string", "minLength": 1}
      }
    },
    "history": {
      "type": "object",
      "additionalProperties": false,
      "required": ["listing_events", "recorded_transfers", "ownership_events", "assessments", "tax_events", "valuations"],
      "properties": {
        "listing_events": {"type": "array", "items": {"$ref": "#/$defs/listingEvent"}},
        "recorded_transfers": {"type": "array", "items": {"$ref": "#/$defs/recordedTransfer"}},
        "ownership_events": {"type": "array", "items": {"$ref": "#/$defs/ownershipEvent"}},
        "assessments": {"type": "array", "items": {"$ref": "#/$defs/assessment"}},
        "tax_events": {"type": "array", "items": {"$ref": "#/$defs/taxEvent"}},
        "valuations": {"type": "array", "items": {"$ref": "#/$defs/valuation"}}
      }
    },
    "areaProfileReference": {
      "type": "object",
      "additionalProperties": false,
      "required": ["geoid", "geography_type", "release_id", "assignment_method", "href"],
      "properties": {
        "geoid": {"type": "string", "minLength": 1},
        "geography_type": {"enum": ["country", "region", "state", "province", "county", "municipality", "district", "postal_code", "zcta", "tract", "block_group", "statistical_area", "custom"]},
        "release_id": {"type": "string", "minLength": 1},
        "geography_vintage": {"type": "string", "minLength": 1},
        "assignment_method": {"type": "string", "minLength": 1},
        "href": {"type": "string", "pattern": "^/v1/places\\?geoid="}
      }
    },
    "context": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "area_profile_ref": {"$ref": "#/$defs/areaProfileReference"},
        "institutional": {
          "type": "object",
          "description": "Country-neutral parcel, building, development, access, hazard and permit intelligence.",
          "additionalProperties": true
        }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_id", "source_record_id", "record_kind"],
      "properties": {
        "source_id": {"type": "string", "minLength": 1},
        "source_record_id": {"type": "string", "minLength": 1},
        "record_kind": {"type": "string", "minLength": 1},
        "vintage": {"type": "string", "minLength": 1},
        "source_url": {"type": "string", "format": "uri"}
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["evidence", "fact_sources", "geography_assignment"],
      "properties": {
        "evidence": {"type": "array", "items": {"$ref": "#/$defs/evidence"}},
        "fact_sources": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^[a-z][a-z0-9_.]{0,199}$": {"$ref": "#/$defs/stringList"}
          }
        },
        "geography_assignment": {"$ref": "#/$defs/geographyAssignment"}
      }
    },
    "geographyAssignment": {
      "type": "object",
      "additionalProperties": false,
      "required": ["pack_version", "resolver_version", "precision", "confidence", "location_fingerprint", "evidence", "unresolved"],
      "properties": {
        "pack_version": {"type": "string", "minLength": 1},
        "resolver_version": {"type": "string", "minLength": 1},
        "precision": {"type": "string", "minLength": 1},
        "confidence": {"type": "number", "minimum": 0, "maximum": 1},
        "location_fingerprint": {"type": "string", "minLength": 1},
        "evidence": {
          "type": "array",
          "items": {"$ref": "#/$defs/geographyEvidence"}
        },
        "unresolved": {"$ref": "#/$defs/stringList"}
      }
    },
    "geographyEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["field", "method"],
      "properties": {
        "field": {"type": "string", "minLength": 1},
        "method": {"type": "string", "minLength": 1},
        "place_id": {"type": "string", "minLength": 1},
        "value": {"type": "string", "minLength": 1}
      }
    }
  }
}
