{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "A5B API v1.0",
  "$defs": {
    "request": {
      "type": "object",
      "properties": {
        "latitude": {
          "type": "number",
          "minimum": -90,
          "maximum": 90
        },
        "longitude": {
          "type": "number",
          "minimum": -180,
          "maximum": 180
        },
        "uncertainty_m": {
          "type": "number",
          "minimum": 0,
          "maximum": 200
        },
        "radius_m": {
          "type": "number",
          "minimum": 1,
          "maximum": 100
        },
        "limit": {
          "type": "integer",
          "minimum": 1,
          "maximum": 50
        },
        "region_id": {
          "enum": [
            "BRONX_2565_PILOT",
            "BRONX_2266",
            "MANHATTAN_829"
          ]
        },
        "offset": {
          "type": "integer",
          "minimum": 0,
          "maximum": 200
        }
      },
      "required": [
        "latitude",
        "longitude",
        "uncertainty_m"
      ],
      "additionalProperties": false
    },
    "fact": {
      "type": "object",
      "properties": {
        "field": {
          "enum": [
            "yearbuilt",
            "numfloors",
            "bldgclass",
            "unitsres"
          ]
        },
        "text": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "source_value": {
          "type": "string"
        },
        "bbl": {
          "type": "string",
          "pattern": "[12]\\d{9}"
        },
        "scope": {
          "const": "TAX_LOT"
        },
        "source_date": {
          "type": "string",
          "pattern": "\\d{4}-\\d{2}-\\d{2}"
        }
      },
      "required": [
        "field",
        "text",
        "source_value",
        "bbl",
        "scope",
        "source_date"
      ],
      "additionalProperties": false
    },
    "provenance": {
      "type": "object",
      "properties": {
        "agency": {
          "type": "string"
        },
        "dataset": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "source_date": {
          "type": "string"
        },
        "acquired_at": {
          "type": "string"
        },
        "snapshot_sha256": {
          "type": "string",
          "pattern": "[a-f0-9]{64}"
        },
        "page": {
          "type": "integer"
        },
        "row": {
          "type": "integer"
        }
      },
      "required": [
        "agency",
        "dataset",
        "version",
        "source_date",
        "acquired_at",
        "snapshot_sha256",
        "page",
        "row"
      ],
      "additionalProperties": false
    },
    "card": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "api_version": {
              "const": "1.0"
            },
            "target_id": {
              "type": "string"
            },
            "bbl": {
              "type": "string",
              "pattern": "[12]\\d{9}"
            },
            "bin": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "[12]\\d{6}"
                },
                {
                  "type": "null"
                }
              ]
            },
            "address": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "status": {
              "const": "READY_PROVISIONAL"
            },
            "facts": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/fact"
              },
              "minItems": 2,
              "maxItems": 3
            },
            "facts_scope": {
              "const": "TAX_LOT"
            },
            "provenance": {
              "$ref": "#/$defs/provenance"
            },
            "field_verified": {
              "const": false
            },
            "automatic_recognition_allowed": {
              "const": false
            }
          },
          "required": [
            "api_version",
            "target_id",
            "bbl",
            "bin",
            "address",
            "status",
            "facts",
            "facts_scope",
            "provenance",
            "field_verified",
            "automatic_recognition_allowed"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "api_version": {
              "const": "1.0"
            },
            "target_id": {
              "type": "string"
            },
            "bbl": {
              "type": "string",
              "pattern": "[12]\\d{9}"
            },
            "bin": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "[12]\\d{6}"
                },
                {
                  "type": "null"
                }
              ]
            },
            "address": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "status": {
              "enum": [
                "INSUFFICIENT_FACTS",
                "STALE"
              ]
            },
            "facts": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/fact"
              },
              "maxItems": 0
            },
            "facts_scope": {
              "const": "TAX_LOT"
            },
            "provenance": {
              "$ref": "#/$defs/provenance"
            },
            "field_verified": {
              "const": false
            },
            "automatic_recognition_allowed": {
              "const": false
            }
          },
          "required": [
            "api_version",
            "target_id",
            "bbl",
            "bin",
            "address",
            "status",
            "facts",
            "facts_scope",
            "provenance",
            "field_verified",
            "automatic_recognition_allowed"
          ],
          "additionalProperties": false
        }
      ]
    },
    "anchor": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "point": {
          "type": "array",
          "items": {
            "type": "number"
          },
          "minItems": 2,
          "maxItems": 2
        },
        "baseline": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 2,
            "maxItems": 2
          },
          "minItems": 2,
          "maxItems": 2
        },
        "normal_bearing_degrees": {
          "type": "number",
          "minimum": 0,
          "maximum": 360
        },
        "street_side": {
          "type": "string"
        },
        "crs": {
          "const": "EPSG:4326"
        },
        "height": {
          "type": "null"
        },
        "review_state": {
          "const": "PROVISIONAL"
        },
        "field_review": {
          "const": "PENDING"
        },
        "source_method": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "point",
        "baseline",
        "normal_bearing_degrees",
        "street_side",
        "crs",
        "height",
        "review_state",
        "field_review",
        "source_method"
      ],
      "additionalProperties": false
    },
    "candidate": {
      "type": "object",
      "properties": {
        "target_id": {
          "type": "string"
        },
        "bbl": {
          "type": "string",
          "pattern": "[12]\\d{9}"
        },
        "bin": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "[12]\\d{6}"
            },
            {
              "type": "null"
            }
          ]
        },
        "addresses": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "distance_m": {
          "type": "number",
          "minimum": 0
        },
        "footprint": {
          "anyOf": [
            {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "type": {
                      "const": "Polygon"
                    },
                    "coordinates": {
                      "type": "array",
                      "items": {
                        "type": "array",
                        "items": {
                          "type": "array",
                          "items": {
                            "type": "number"
                          },
                          "minItems": 2,
                          "maxItems": 2
                        },
                        "minItems": 4
                      },
                      "minItems": 1
                    }
                  },
                  "required": [
                    "type",
                    "coordinates"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "type": {
                      "const": "MultiPolygon"
                    },
                    "coordinates": {
                      "type": "array",
                      "items": {
                        "type": "array",
                        "items": {
                          "type": "array",
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "number"
                            },
                            "minItems": 2,
                            "maxItems": 2
                          },
                          "minItems": 4
                        },
                        "minItems": 1
                      },
                      "minItems": 1
                    }
                  },
                  "required": [
                    "type",
                    "coordinates"
                  ],
                  "additionalProperties": false
                }
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "parcel_geometry": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "type": {
                  "const": "Polygon"
                },
                "coordinates": {
                  "type": "array",
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "number"
                      },
                      "minItems": 2,
                      "maxItems": 2
                    },
                    "minItems": 4
                  },
                  "minItems": 1
                }
              },
              "required": [
                "type",
                "coordinates"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "type": {
                  "const": "MultiPolygon"
                },
                "coordinates": {
                  "type": "array",
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "array",
                        "items": {
                          "type": "number"
                        },
                        "minItems": 2,
                        "maxItems": 2
                      },
                      "minItems": 4
                    },
                    "minItems": 1
                  },
                  "minItems": 1
                }
              },
              "required": [
                "type",
                "coordinates"
              ],
              "additionalProperties": false
            }
          ]
        },
        "facade_anchors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/anchor"
          }
        },
        "provenance": {
          "type": "object",
          "properties": {
            "snapshot_sha256": {
              "type": "string",
              "pattern": "[a-f0-9]{64}"
            },
            "geometry_source": {
              "type": "string"
            },
            "join_ids": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "snapshot_sha256",
            "geometry_source",
            "join_ids"
          ],
          "additionalProperties": false
        },
        "review_state": {
          "const": "PROVISIONAL"
        },
        "automatic_recognition_allowed": {
          "const": false
        }
      },
      "required": [
        "target_id",
        "bbl",
        "bin",
        "addresses",
        "distance_m",
        "footprint",
        "parcel_geometry",
        "facade_anchors",
        "provenance",
        "review_state",
        "automatic_recognition_allowed"
      ],
      "additionalProperties": false
    },
    "nearby": {
      "type": "object",
      "properties": {
        "api_version": {
          "const": "1.0"
        },
        "request_id": {
          "type": "string"
        },
        "query_radius_m": {
          "type": "number"
        },
        "uncertainty_m": {
          "type": "number"
        },
        "status": {
          "enum": [
            "CANDIDATES",
            "OUTSIDE_COVERAGE",
            "NO_CANDIDATES"
          ]
        },
        "candidates": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/candidate"
          },
          "maxItems": 50
        },
        "total_matches": {
          "type": "integer",
          "minimum": 0
        },
        "truncated": {
          "type": "boolean"
        },
        "selection": {
          "const": "MANUAL_CHOICE_OR_ABSTAIN"
        },
        "dataset_version": {
          "type": "string"
        }
      },
      "required": [
        "api_version",
        "request_id",
        "query_radius_m",
        "uncertainty_m",
        "status",
        "candidates",
        "total_matches",
        "truncated",
        "selection",
        "dataset_version"
      ],
      "additionalProperties": false
    },
    "freshness": {
      "type": "object",
      "properties": {
        "generated_at": {
          "type": "string"
        },
        "expires_at": {
          "type": "string"
        },
        "source_date": {
          "type": "string"
        },
        "source_max_age_days": {
          "const": 180
        },
        "field_verified": {
          "const": false
        }
      },
      "required": [
        "generated_at",
        "expires_at",
        "source_date",
        "source_max_age_days",
        "field_verified"
      ],
      "additionalProperties": false
    },
    "sync": {
      "type": "object",
      "properties": {
        "api_version": {
          "const": "1.0"
        },
        "request_id": {
          "type": "string"
        },
        "scope": {
          "enum": [
            "BRONX_2565_PILOT",
            "BRONX_2266",
            "MANHATTAN_829"
          ]
        },
        "dataset_version": {
          "type": "string"
        },
        "freshness": {
          "$ref": "#/$defs/freshness"
        },
        "nearby": {
          "$ref": "#/$defs/nearby"
        },
        "cards": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/card"
          },
          "maxItems": 50
        },
        "offline_policy": {
          "const": "EXACT_QUERY_CACHE_UNTIL_EXPIRY_THEN_UNAVAILABLE"
        }
      },
      "required": [
        "api_version",
        "request_id",
        "scope",
        "dataset_version",
        "freshness",
        "nearby",
        "cards",
        "offline_policy"
      ],
      "additionalProperties": false
    }
  }
}
