{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openplacerules.org/spec/place-rules.schema.json",
  "title": "OpenPlaceRules file (v0.1)",
  "description": "Machine-readable rules a place publishes at /.well-known/place-rules.json for camera glasses, recording, AI capture, robots and drones.",
  "type": "object",
  "required": [
    "spec",
    "place",
    "rules",
    "updated"
  ],
  "additionalProperties": false,
  "$defs": {
    "value": {
      "enum": [
        "allowed",
        "restricted",
        "prohibited"
      ]
    },
    "ruleset": {
      "type": "object",
      "description": "Activity -> value. Omitted activities are 'unspecified' (no claim).",
      "additionalProperties": false,
      "properties": {
        "camera_glasses": {
          "$ref": "#/$defs/value",
          "description": "Wearing/using glasses or other wearables with a camera or microphone."
        },
        "recording": {
          "$ref": "#/$defs/value",
          "description": "Taking photos, video or audio with any device."
        },
        "ai_capture": {
          "$ref": "#/$defs/value",
          "description": "Feeding live camera/mic input to an AI (e.g. scene description, face recognition, transcription)."
        },
        "robots": {
          "$ref": "#/$defs/value",
          "description": "Ground robots: delivery robots, humanoids, mobile robots."
        },
        "drones": {
          "$ref": "#/$defs/value",
          "description": "Take-off, landing or flight of uncrewed aircraft."
        }
      }
    },
    "hours": {
      "type": "object",
      "required": [
        "days",
        "from",
        "to"
      ],
      "additionalProperties": false,
      "properties": {
        "days": {
          "type": "array",
          "items": {
            "enum": [
              "mon",
              "tue",
              "wed",
              "thu",
              "fri",
              "sat",
              "sun"
            ]
          },
          "minItems": 1
        },
        "from": {
          "type": "string",
          "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$"
        },
        "to": {
          "type": "string",
          "pattern": "^([01][0-9]|2[0-4]):[0-5][0-9]$"
        }
      }
    },
    "geometry": {
      "description": "Where the rules apply. A circle (center + radius) or a GeoJSON Polygon/MultiPolygon.",
      "oneOf": [
        {
          "type": "object",
          "required": [
            "type",
            "center",
            "radius_m"
          ],
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "circle"
            },
            "center": {
              "type": "array",
              "prefixItems": [
                {
                  "type": "number",
                  "minimum": -90,
                  "maximum": 90
                },
                {
                  "type": "number",
                  "minimum": -180,
                  "maximum": 180
                }
              ],
              "minItems": 2,
              "maxItems": 2,
              "description": "[lat, lng]"
            },
            "radius_m": {
              "type": "number",
              "exclusiveMinimum": 0
            }
          }
        },
        {
          "type": "object",
          "required": [
            "type",
            "coordinates"
          ],
          "additionalProperties": false,
          "properties": {
            "type": {
              "enum": [
                "Polygon",
                "MultiPolygon"
              ]
            },
            "coordinates": {
              "type": "array",
              "minItems": 1
            }
          },
          "if": {
            "properties": {
              "type": {
                "const": "Polygon"
              }
            }
          },
          "then": {
            "properties": {
              "coordinates": {
                "items": {
                  "type": "array",
                  "items": {
                    "type": "array",
                    "prefixItems": [
                      {
                        "type": "number",
                        "minimum": -180,
                        "maximum": 180
                      },
                      {
                        "type": "number",
                        "minimum": -90,
                        "maximum": 90
                      }
                    ],
                    "minItems": 2,
                    "description": "[lng, lat] (GeoJSON order)"
                  },
                  "minItems": 4,
                  "description": "closed ring: first position == last"
                }
              }
            }
          },
          "else": {
            "properties": {
              "coordinates": {
                "items": {
                  "type": "array",
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "prefixItems": [
                        {
                          "type": "number",
                          "minimum": -180,
                          "maximum": 180
                        },
                        {
                          "type": "number",
                          "minimum": -90,
                          "maximum": 90
                        }
                      ],
                      "minItems": 2,
                      "description": "[lng, lat] (GeoJSON order)"
                    },
                    "minItems": 4,
                    "description": "closed ring: first position == last"
                  },
                  "minItems": 1
                }
              }
            }
          }
        }
      ]
    }
  },
  "properties": {
    "spec": {
      "const": "place-rules/0.1",
      "description": "Spec version. Readers MUST ignore unknown fields of a higher minor version."
    },
    "updated": {
      "type": "string",
      "format": "date-time"
    },
    "expires": {
      "type": "string",
      "format": "date-time",
      "description": "Optional. After this time readers SHOULD refetch and treat the file as stale."
    },
    "place": {
      "type": "object",
      "required": [
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "address": {
          "type": "string"
        },
        "geometry": {
          "$ref": "#/$defs/geometry"
        },
        "timezone": {
          "type": "string",
          "description": "IANA zone, e.g. Asia/Bangkok, used for hours."
        }
      }
    },
    "rules": {
      "$ref": "#/$defs/ruleset",
      "description": "Default rules for the whole place."
    },
    "zones": {
      "type": "array",
      "description": "Areas or times that override the defaults. The most specific matching zone wins; on a tie the most restrictive value wins.",
      "items": {
        "type": "object",
        "required": [
          "name",
          "rules"
        ],
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string"
          },
          "geometry": {
            "$ref": "#/$defs/geometry"
          },
          "hours": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/hours"
            }
          },
          "rules": {
            "$ref": "#/$defs/ruleset"
          },
          "note": {
            "type": "string"
          }
        }
      }
    },
    "conditions": {
      "type": "string",
      "maxLength": 2000,
      "description": "Plain-language detail for 'restricted' (e.g. 'personal photos only, no flash'). Long enough for an official house-rule text such as the Dutch AP standard wording."
    },
    "exceptions": {
      "type": "string",
      "maxLength": 2000,
      "description": "e.g. medical/accessibility exemptions, permits. Long enough for an official house-rule exemption such as the Dutch AP standard wording."
    },
    "contact": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "email": {
          "type": "string",
          "format": "email"
        },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Where to ask for permission or report a problem."
        }
      }
    },
    "source": {
      "type": "string",
      "format": "uri",
      "description": "Human-readable policy page this file reflects."
    },
    "verification": {
      "type": "object",
      "description": "How a registry can confirm this file is published by the place's owner.",
      "additionalProperties": false,
      "properties": {
        "method": {
          "enum": [
            "well-known",
            "meta",
            "dns"
          ]
        },
        "token": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{16,128}$"
        }
      }
    }
  }
}