{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://trinetrahq.com/schemas/sangam/1.0/zone.schema.json",
  "title": "SANGAM Zone",
  "description": "A polygon zone or a virtual line that alert rules evaluate tracks against. Points are [lat, lon] pairs. Polygons are implicitly closed. For a line, the interior side is to the right when walking from the first point to the last.",
  "type": "object",
  "required": ["type", "schema_version", "id", "name", "kind", "points"],
  "properties": {
    "type": {"const": "zone", "description": "Record type."},
    "schema_version": {"$ref": "common.schema.json#/$defs/schemaVersion"},
    "id": {"$ref": "common.schema.json#/$defs/id", "description": "Zone id, used as zone_id or line_id in alerts."},
    "name": {"type": "string", "minLength": 1, "maxLength": 120},
    "kind": {"enum": ["polygon", "line"]},
    "points": {
      "type": "array",
      "minItems": 2,
      "items": {"$ref": "common.schema.json#/$defs/latLon"}
    },
    "purpose": {"type": "string", "maxLength": 280},
    "policy": {
      "description": "Which tracks fire the rule and at what level.",
      "type": "object",
      "properties": {
        "labels": {"type": "array", "items": {"$ref": "common.schema.json#/$defs/label"}, "uniqueItems": true},
        "exclude_registered": {"type": "boolean"},
        "min_confidence": {"type": "number", "minimum": 0, "maximum": 1},
        "level": {"$ref": "common.schema.json#/$defs/level"},
        "level_by_label": {
          "description": "Overrides of level for particular labels.",
          "type": "object",
          "propertyNames": {"$ref": "common.schema.json#/$defs/label"},
          "additionalProperties": {"$ref": "common.schema.json#/$defs/level"}
        },
        "direction": {"enum": ["inbound", "outbound", "both"]}
      },
      "additionalProperties": false
    },
    "setback_m": {"type": "number", "minimum": 0, "description": "For a virtual line derived from a boundary: offset toward the interior, metres."},
    "active": {"type": "boolean"},
    "valid_from": {"$ref": "common.schema.json#/$defs/time"},
    "valid_to": {"$ref": "common.schema.json#/$defs/time"},
    "attributes": {"$ref": "common.schema.json#/$defs/attributes"},
    "simulated": {"type": "boolean"}
  },
  "if": {"properties": {"kind": {"const": "polygon"}}, "required": ["kind"]},
  "then": {"properties": {"points": {"minItems": 3}}},
  "additionalProperties": false,
  "examples": [
    {
      "type": "zone",
      "schema_version": "1.0",
      "id": "Z-LAND-A",
      "name": "Landing point A",
      "kind": "polygon",
      "points": [[22.5841, 88.9361], [22.5843, 88.9372], [22.5832, 88.9374], [22.5830, 88.9363]],
      "purpose": "Informal landing point on the interior bank. Notional.",
      "policy": {"labels": ["small_boat", "large_vessel", "person", "animal", "unknown"], "exclude_registered": true, "min_confidence": 0.4, "level": "warning"},
      "active": true,
      "simulated": true
    }
  ]
}
