{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://broker.ma/observatoire/casablanca/2026-10-26/schema.json",
  "title": "Observatoire Broker.ma — observations (v4)",
  "type": "object",
  "required": [
    "edition",
    "city",
    "price_nature",
    "definitions",
    "fresh",
    "historical"
  ],
  "additionalProperties": false,
  "properties": {
    "edition": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "city": {
      "type": "string"
    },
    "price_nature": {
      "const": "asking_not_transaction"
    },
    "definitions": {
      "type": "object",
      "required": [
        "observed_at",
        "verification_grade"
      ]
    },
    "fresh": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/fresh"
      }
    },
    "historical": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/historical"
      }
    }
  },
  "$defs": {
    "common": {
      "type": "object",
      "required": [
        "observation_uid",
        "id",
        "zone",
        "asset_type",
        "transaction",
        "source_url",
        "source",
        "observed_at",
        "record_status",
        "eligible_displayed_statistics",
        "eligible_ht_hc_statistics"
      ],
      "properties": {
        "observation_uid": {
          "type": "string",
          "pattern": "^casablanca-\\d{4}-\\d{2}-\\d{2}-[A-Za-z0-9-]+$"
        },
        "id": {
          "type": "string"
        },
        "zone": {
          "enum": [
            "Sidi Maârouf",
            "Oasis",
            "Route d’El Jadida",
            "Ferme Bretonne"
          ]
        },
        "asset_type": {
          "enum": [
            "bureau",
            "local_commercial"
          ]
        },
        "transaction": {
          "enum": [
            "vente",
            "location"
          ]
        },
        "area_m2": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0
        },
        "price_mad": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "rent_ht_hc_mad": {
          "type": [
            "number",
            "null"
          ]
        },
        "computed_ratio_mad_m2": {
          "type": [
            "number",
            "null"
          ]
        },
        "ratio_unit": {
          "enum": [
            "MAD/m²",
            "MAD/m²/mois"
          ]
        },
        "tax_basis": {
          "type": [
            "string",
            "null"
          ]
        },
        "area_basis": {
          "type": [
            "string",
            "null"
          ]
        },
        "source": {
          "type": "string"
        },
        "source_url": {
          "type": "string",
          "format": "uri"
        },
        "observed_at": {
          "type": "string",
          "format": "date"
        },
        "verification_grade": {
          "enum": [
            "B",
            "C"
          ]
        },
        "eligible_displayed_statistics": {
          "type": "boolean"
        },
        "eligible_ht_hc_statistics": {
          "const": false
        },
        "notes": {
          "type": "string"
        }
      },
      "not": {
        "anyOf": [
          {
            "required": [
              "owner_name"
            ]
          },
          {
            "required": [
              "owner_phone"
            ]
          },
          {
            "required": [
              "owner_email"
            ]
          },
          {
            "required": [
              "phone"
            ]
          },
          {
            "required": [
              "email"
            ]
          },
          {
            "required": [
              "mandate_reference"
            ]
          },
          {
            "required": [
              "commission_rate"
            ]
          },
          {
            "required": [
              "internal_notes"
            ]
          }
        ]
      }
    },
    "fresh": {
      "allOf": [
        {
          "$ref": "#/$defs/common"
        },
        {
          "type": "object",
          "required": [
            "record_status",
            "availability_confirmed",
            "web_page_checked",
            "unit_key",
            "same_listing_as_historical",
            "rent_ht_hc_mad",
            "office_interior_m2",
            "ground_floor_m2",
            "mezzanine_m2",
            "upper_floor_m2",
            "terrace_m2",
            "parking_area_m2",
            "advertised_area_m2",
            "total_built_area_m2",
            "area_conflict",
            "charge_inclusion",
            "source_reference"
          ],
          "properties": {
            "record_status": {
              "const": "fresh"
            },
            "availability_confirmed": {
              "const": false
            },
            "web_page_checked": {
              "const": true
            },
            "currency": {
              "const": "MAD"
            },
            "price_period": {
              "enum": [
                "month",
                null
              ]
            },
            "asking_ratio_mad_m2": {
              "type": [
                "number",
                "null"
              ]
            },
            "unit_key": {
              "type": "string"
            },
            "same_listing_as_historical": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "has_mezzanine": {
              "type": "boolean"
            },
            "office_interior_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "ground_floor_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "mezzanine_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "upper_floor_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "terrace_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "parking_area_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "advertised_area_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "total_built_area_m2": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "area_conflict": {
              "type": [
                "boolean",
                "null"
              ]
            },
            "charge_inclusion": {
              "type": [
                "string",
                "null"
              ]
            },
            "source_reference": {
              "type": [
                "string",
                "null"
              ]
            },
            "suspected_duplicate_of": {
              "type": "string"
            },
            "duplicate_status": {
              "const": "diffusion_secondaire_meme_lot_probable"
            }
          },
          "if": {
            "required": [
              "suspected_duplicate_of"
            ]
          },
          "then": {
            "properties": {
              "eligible_displayed_statistics": {
                "const": false
              }
            }
          }
        }
      ]
    },
    "historical": {
      "allOf": [
        {
          "$ref": "#/$defs/common"
        },
        {
          "type": "object",
          "required": [
            "record_status",
            "historical_only",
            "label"
          ],
          "properties": {
            "record_status": {
              "const": "historical"
            },
            "historical_only": {
              "const": true
            },
            "label": {
              "type": "string"
            },
            "eligible_displayed_statistics": {
              "const": false
            },
            "derived_from_edition": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "original_observation_uid": {
              "type": [
                "string",
                "null"
              ]
            },
            "eligible_ht_hc_statistics": {
              "const": false
            }
          }
        }
      ]
    }
  }
}
