{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://viatrail.app/schema/viatrail-extensions.schema.json",
  "title": "Viatrail extensions to VNX",
  "description": "What Viatrail reads and writes beyond VNX 0.11.0: its data record types (VNX §5), its style and behaviour records, and its two application keys (VNX §3.9). Validate a whole document against this schema to check the application keys. Each data record type is a $defs entry named by its @type; check a record against the entry its @type names. Generated from the app's code.",
  "x-vnx-version": "0.11.0",
  "x-namespace": "app.viatrail.",
  "x-record-types": [
    "app.viatrail.camp",
    "app.viatrail.shelter",
    "app.viatrail.hotel",
    "app.viatrail.shop",
    "app.viatrail.settlement",
    "app.viatrail.water",
    "app.viatrail.tag",
    "app.viatrail.note",
    "app.viatrail.photo",
    "app.viatrail.route",
    "app.viatrail.terrain",
    "app.viatrail.hazard",
    "app.viatrail.routing",
    "app.viatrail.compute-failed",
    "app.viatrail.style.line",
    "app.viatrail.style.fill",
    "app.viatrail.style.card",
    "app.viatrail.style.marker",
    "app.viatrail.behaviour",
    "app.viatrail.style.marker.item",
    "app.viatrail.style.marker.data"
  ],
  "x-application-keys": [
    "app.viatrail.datatypes",
    "app.viatrail.rulesets"
  ],
  "x-attachment-paths": {
    "app.viatrail.photo": "app.viatrail.photo/{id}.jpg"
  },
  "type": "object",
  "properties": {
    "app.viatrail.datatypes": {
      "$ref": "#/$defs/app.viatrail.datatypes"
    },
    "app.viatrail.rulesets": {
      "$ref": "#/$defs/app.viatrail.rulesets"
    }
  },
  "$defs": {
    "app.viatrail.camp": {
      "title": "Camp",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.camp"
        },
        "rating": {
          "title": "Rating",
          "description": "Overall rating?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "flat": {
          "title": "Flat",
          "description": "How flat is the ground?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "sheltered": {
          "title": "Sheltered",
          "description": "How sheltered is the camp from the wind?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "water": {
          "title": "Water",
          "description": "How convenient / clean is the water source?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "booking": {
          "title": "Booking",
          "description": "Does the camp need booking?",
          "x-kind": "bool",
          "type": "boolean"
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]"
      ],
      "x-internal": false
    },
    "app.viatrail.shelter": {
      "title": "Shelter",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.shelter"
        },
        "rating": {
          "title": "Rating",
          "description": "Overall rating?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "booking": {
          "title": "Booking",
          "description": "Does the shelter need booking?",
          "x-kind": "bool",
          "type": "boolean"
        },
        "beds": {
          "title": "Beds",
          "description": "Approximately how many beds?",
          "x-kind": "integer",
          "type": "integer"
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]"
      ],
      "x-internal": false
    },
    "app.viatrail.hotel": {
      "title": "Hotel",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.hotel"
        },
        "rating": {
          "title": "Rating",
          "description": "Overall rating?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "booking": {
          "title": "Booking",
          "description": "Does the hotel need booking?",
          "x-kind": "bool",
          "type": "boolean"
        },
        "rooms": {
          "title": "Rooms",
          "description": "Approximately how many rooms?",
          "x-kind": "integer",
          "type": "integer"
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]"
      ],
      "x-internal": false
    },
    "app.viatrail.shop": {
      "title": "Shop",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.shop"
        },
        "resupply": {
          "title": "Resupply",
          "description": "What can you resupply here?",
          "x-kind": "enum",
          "type": "string",
          "oneOf": [
            {
              "const": "kiosk",
              "title": "Kiosk",
              "description": "Snacks, drinks and odds and ends."
            },
            {
              "const": "grocery",
              "title": "Grocery",
              "description": "Dried and long-life food."
            },
            {
              "const": "market",
              "title": "Market",
              "description": "Full range including fresh food, fruit and vegetables."
            }
          ]
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]"
      ],
      "x-internal": false
    },
    "app.viatrail.settlement": {
      "title": "Settlement",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.settlement"
        },
        "hotels": {
          "title": "Hotels",
          "description": "Does this settlement have hotels?",
          "x-kind": "bool",
          "type": "boolean"
        },
        "resupply": {
          "title": "Resupply",
          "description": "What can you resupply here?",
          "x-kind": "enum",
          "type": "string",
          "oneOf": [
            {
              "const": "kiosk",
              "title": "Kiosk",
              "description": "Snacks, drinks and odds and ends."
            },
            {
              "const": "grocery",
              "title": "Grocery",
              "description": "Dried and long-life food."
            },
            {
              "const": "market",
              "title": "Market",
              "description": "Full range including fresh food, fruit and vegetables."
            }
          ]
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]",
        "areas[]",
        "networks[].areas[]"
      ],
      "x-internal": false
    },
    "app.viatrail.water": {
      "title": "Water",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.water"
        },
        "rating": {
          "title": "Rating",
          "description": "Overall rating?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "seasonal": {
          "title": "Seasonal",
          "description": "Is this water source dry in some seasons?",
          "x-kind": "bool",
          "type": "boolean"
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]"
      ],
      "x-internal": false
    },
    "app.viatrail.tag": {
      "title": "Tag",
      "description": "A free-text tag. Any application may write it. It is internal only in that the app does not list it as a data type: it shows tags as chips. A data type definition cannot name this type.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.tag"
        },
        "value": {
          "title": "Value",
          "x-kind": "text",
          "type": "string"
        }
      },
      "x-vnx-locations": [
        "networks[]",
        "tracks[]",
        "points[]",
        "networks[].points[]",
        "networks[].highlights[]",
        "plans[]",
        "areas[]",
        "networks[].areas[]"
      ],
      "x-internal": true
    },
    "app.viatrail.note": {
      "title": "Note",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.note"
        },
        "text": {
          "title": "Text",
          "x-kind": "markdown",
          "type": "string",
          "contentMediaType": "text/markdown"
        }
      },
      "x-vnx-locations": [
        "networks[]",
        "tracks[]",
        "points[]",
        "networks[].points[]",
        "networks[].highlights[]",
        "plans[]",
        "areas[]",
        "networks[].areas[]"
      ],
      "x-internal": false
    },
    "app.viatrail.photo": {
      "title": "Photo",
      "description": "A data type definition cannot name this type. Its photos travel only in a .vnz, as the files it names.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.photo"
        },
        "photos": {
          "title": "Photos",
          "x-kind": "reference",
          "type": "array",
          "items": {
            "type": "string",
            "description": "The archive entry of one photo, a JPEG, in the .vnz that holds the document.",
            "x-attachment-path": "app.viatrail.photo/{id}.jpg"
          }
        }
      },
      "x-vnx-locations": [
        "networks[]",
        "tracks[]",
        "points[]",
        "networks[].points[]",
        "networks[].highlights[]",
        "plans[]",
        "areas[]",
        "networks[].areas[]"
      ],
      "x-internal": false
    },
    "app.viatrail.route": {
      "title": "Route",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.route"
        },
        "rating": {
          "title": "Rating",
          "description": "Overall rating?",
          "x-kind": "stars",
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        }
      },
      "x-vnx-locations": [
        "networks[].highlights[]"
      ],
      "x-internal": false
    },
    "app.viatrail.terrain": {
      "title": "Terrain",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.terrain"
        },
        "terrain": {
          "title": "Type",
          "description": "Terrain type",
          "x-kind": "enum",
          "type": "string",
          "oneOf": [
            {
              "const": "major_road",
              "title": "Major Road"
            },
            {
              "const": "minor_road",
              "title": "Minor Road"
            },
            {
              "const": "trail",
              "title": "Trail"
            },
            {
              "const": "cross_country",
              "title": "Cross-Country"
            },
            {
              "const": "bush_bash",
              "title": "Bush Bash"
            }
          ]
        }
      },
      "x-vnx-locations": [
        "networks[].highlights[]"
      ],
      "x-internal": false
    },
    "app.viatrail.hazard": {
      "title": "Hazard",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.hazard"
        },
        "description": {
          "title": "Description",
          "description": "Description of the hazard",
          "x-kind": "markdown",
          "type": "string",
          "contentMediaType": "text/markdown"
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]",
        "networks[].highlights[]",
        "areas[]",
        "networks[].areas[]"
      ],
      "x-internal": false
    },
    "app.viatrail.routing": {
      "title": "Routing (internal)",
      "description": "Written by Viatrail; do not write.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.routing"
        },
        "source": {
          "type": "string",
          "enum": [
            "engine",
            "gpx-import",
            "gps-recording",
            "user-snap",
            "user-drawn",
            "copied"
          ],
          "description": "How the arc's line was made. Only \"engine\" marks the arc as routed by an engine; with any other value, or no record, Viatrail does not route the arc again."
        },
        "config": {
          "type": "object",
          "description": "The engine settings the arc was routed with. When source is \"engine\", config must have library-enabled, base-map-enabled, cross-country-enabled and forest-avoidance, or the import fails.",
          "properties": {
            "library-enabled": {
              "type": "boolean",
              "description": "Whether the route may use the user's own saved lines and networks."
            },
            "base-map-enabled": {
              "type": "boolean",
              "description": "Whether the route may use OpenStreetMap trails."
            },
            "cross-country-enabled": {
              "type": "boolean",
              "description": "Whether the route may cross open ground away from any trail."
            },
            "max-slope-deg": {
              "type": "number",
              "description": "The steepest slope the route may climb, in degrees, from 5 to 60."
            },
            "hill-avoidance": {
              "type": "number",
              "description": "How strongly the route avoids climbing, from 0 (not at all) to 1 (strongly)."
            },
            "forest-avoidance": {
              "type": "number",
              "description": "How strongly the route avoids forest off trail, from 0 (forest costs as open ground) to 1 (strongly)."
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "source"
            ],
            "properties": {
              "source": {
                "const": "engine"
              }
            }
          },
          "then": {
            "required": [
              "config"
            ],
            "properties": {
              "config": {
                "required": [
                  "library-enabled",
                  "base-map-enabled",
                  "cross-country-enabled",
                  "forest-avoidance"
                ]
              }
            }
          }
        }
      ],
      "x-vnx-locations": [
        "plans[].arcs{}",
        "networks[].arcs{}"
      ],
      "x-internal": true
    },
    "app.viatrail.compute-failed": {
      "title": "Routing failed",
      "description": "Written by Viatrail; do not write. Its presence on an arc says the engine could not route it, and the line is a straight placeholder. It has no fields.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.compute-failed"
        }
      },
      "x-vnx-locations": [
        "plans[].arcs{}",
        "networks[].arcs{}"
      ],
      "x-internal": true
    },
    "marker": {
      "type": "object",
      "properties": {
        "icon": {
          "type": "string",
          "pattern": "^(none|(lucide|emoji):.+)$",
          "description": "An icon: \"lucide:<id>\" for a Lucide icon or \"emoji:<id>\" for an emoji. \"none\" draws no glyph. An id the app does not have is dropped with a report."
        },
        "hue": {
          "type": "integer",
          "minimum": 0,
          "maximum": 359
        },
        "intensity": {
          "type": "string",
          "enum": [
            "pale",
            "normal",
            "intense"
          ]
        },
        "darkness": {
          "type": "string",
          "enum": [
            "light",
            "normal",
            "dark"
          ]
        },
        "outline": {
          "type": "string",
          "enum": [
            "circle",
            "square",
            "hexagon",
            "diamond",
            "flag",
            "none"
          ]
        }
      }
    },
    "app.viatrail.style.line": {
      "title": "Line style",
      "description": "How the item's line is drawn: on a plan, a track, a network or an area. In a rule: the line of each item it matches. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.style.line"
        },
        "hue": {
          "type": "integer",
          "minimum": 0,
          "maximum": 359
        },
        "intensity": {
          "type": "string",
          "enum": [
            "pale",
            "normal",
            "intense"
          ]
        },
        "darkness": {
          "type": "string",
          "enum": [
            "light",
            "normal",
            "dark"
          ]
        },
        "width": {
          "type": "integer",
          "enum": [
            2,
            4,
            6
          ]
        },
        "casing": {
          "type": "string",
          "enum": [
            "light",
            "dark"
          ]
        },
        "stripe": {
          "type": "string",
          "enum": [
            "none",
            "solid",
            "dashes",
            "dots"
          ]
        },
        "show-name": {
          "type": "string",
          "enum": [
            "yes",
            "no"
          ]
        }
      },
      "x-vnx-locations": [
        "plans[]",
        "tracks[]",
        "areas[]",
        "networks[].areas[]",
        "networks[]"
      ],
      "x-internal": false
    },
    "app.viatrail.style.fill": {
      "title": "Fill style",
      "description": "How an area is filled. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.style.fill"
        },
        "hue": {
          "type": "integer",
          "minimum": 0,
          "maximum": 359
        },
        "intensity": {
          "type": "string",
          "enum": [
            "pale",
            "normal",
            "intense"
          ]
        },
        "darkness": {
          "type": "string",
          "enum": [
            "light",
            "normal",
            "dark"
          ]
        },
        "strength": {
          "type": "string",
          "enum": [
            "light",
            "medium",
            "strong"
          ]
        },
        "pattern": {
          "type": "string",
          "enum": [
            "solid",
            "hatch",
            "none"
          ]
        }
      },
      "x-vnx-locations": [
        "areas[]",
        "networks[].areas[]"
      ],
      "x-internal": false
    },
    "app.viatrail.style.card": {
      "title": "Card",
      "description": "The item's card on the map. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.style.card"
        },
        "importance": {
          "type": "integer",
          "minimum": -2147483648,
          "maximum": 2147483647,
          "description": "Any whole number a 32-bit signed integer holds. The map places the labels of an item with a higher importance first. 0 is the default."
        },
        "show-card": {
          "type": "string",
          "enum": [
            "yes",
            "no"
          ]
        },
        "tag-fill": {
          "type": "string",
          "enum": [
            "card",
            "solid"
          ]
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]",
        "plans[]",
        "tracks[]",
        "areas[]",
        "networks[].areas[]",
        "networks[]"
      ],
      "x-internal": false
    },
    "app.viatrail.style.marker": {
      "title": "Marker",
      "description": "The item's own marker. A rule styles markers with app.viatrail.style.marker.item and app.viatrail.style.marker.data instead. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.style.marker"
        }
      },
      "allOf": [
        {
          "$ref": "#/$defs/marker"
        }
      ],
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]",
        "plans[]",
        "tracks[]",
        "areas[]",
        "networks[].areas[]",
        "networks[]"
      ],
      "x-internal": false
    },
    "app.viatrail.behaviour": {
      "title": "Behaviour",
      "description": "Whether a tap selects the item. In a rule, hide hides the items it matches; an item cannot hide itself. Write at most one per item or rule. An absent key is Automatic: the rule sets decide. A value the app cannot use is dropped with a report and the rest are kept.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.behaviour"
        },
        "hide": {
          "type": "string",
          "enum": [
            "yes",
            "no"
          ]
        },
        "selectable": {
          "type": "string",
          "enum": [
            "yes",
            "no"
          ],
          "description": "Whether a tap on the map can select the item. It has no effect on a \"waypoint\" or a \"highlight\" item, which is always selectable; an item's own settings on one are refused. \"waypoint\" means a VNX point, top-level or in a network."
        }
      },
      "x-vnx-locations": [
        "points[]",
        "networks[].points[]",
        "plans[]",
        "tracks[]",
        "areas[]",
        "networks[].areas[]",
        "networks[]"
      ],
      "x-internal": false
    },
    "app.viatrail.style.marker.item": {
      "title": "Item markers",
      "description": "A rule's marker for each item kind it lists in item-types: at most one entry per kind. Rules only. \"waypoint\" means a VNX point, top-level or in a network.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.style.marker.item"
        },
        "markers": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "enum": [
                  "waypoint",
                  "plan",
                  "track",
                  "highlight",
                  "area",
                  "network"
                ]
              },
              "marker": {
                "$ref": "#/$defs/marker"
              }
            }
          }
        }
      },
      "x-internal": false
    },
    "app.viatrail.style.marker.data": {
      "title": "Data markers",
      "description": "A rule's data types and their markers: one entry per data type the rule styles, at most one per type, in the rule's order. Rules only. marker-type: none (no marker, no card row), primary (its own marker on the map and its own named row on cards) or secondary (a small icon in one shared row on cards; on the map only when the item has no primary marker, then only the strongest). An entry with only its type picks the type and changes nothing.",
      "type": "object",
      "required": [
        "@type"
      ],
      "properties": {
        "@type": {
          "const": "app.viatrail.style.marker.data"
        },
        "markers": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "type": "string",
                "minLength": 1,
                "description": "The data type's id. The last dot-separated part must start with a letter."
              },
              "marker": {
                "$ref": "#/$defs/marker"
              },
              "marker-type": {
                "enum": [
                  "none",
                  "primary",
                  "secondary"
                ]
              },
              "boost": {
                "type": "integer",
                "minimum": -2147483648,
                "maximum": 2147483647,
                "description": "Any whole number a 32-bit signed integer holds. It adds to the importance of an item with a record of the type, and orders the item's marks and records: within a marker type, a higher boost comes first. 0 is the default."
              }
            }
          }
        }
      },
      "x-internal": false
    },
    "app.viatrail.datatypes": {
      "title": "Data type definitions",
      "description": "Each entry is a data type set: a named set of data type definitions, a library item in Viatrail. Viatrail never writes an empty list.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/datatype-item"
      }
    },
    "datatype-item": {
      "type": "object",
      "required": [
        "name",
        "types"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "The data type set's name. It may be empty."
        },
        "folder": {
          "type": "string",
          "description": "The id of a folder in the same document. Absent or empty: the import places it where the user chooses."
        },
        "pinned": {
          "type": "string",
          "description": "When the data type set was pinned: a VNX timestamp (§4.3)."
        },
        "types": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/datatype-type"
          }
        }
      }
    },
    "datatype-type": {
      "type": "object",
      "description": "One type. A type that breaks a rule is left out at import, alone, with a report; an unknown key is removed with a report.",
      "required": [
        "datatype"
      ],
      "properties": {
        "datatype": {
          "type": "string",
          "minLength": 1,
          "description": "The @type of the records this type describes. Inside app.viatrail. it must be one of the built-in types a definition may name (x-nameable-built-in-types), spelled exactly: such a type is extended, not replaced.",
          "x-nameable-built-in-types": [
            "app.viatrail.camp",
            "app.viatrail.shelter",
            "app.viatrail.hotel",
            "app.viatrail.shop",
            "app.viatrail.settlement",
            "app.viatrail.water",
            "app.viatrail.note",
            "app.viatrail.route",
            "app.viatrail.terrain",
            "app.viatrail.hazard"
          ]
        },
        "label": {
          "allOf": [
            {
              "$ref": "#/$defs/label-map"
            }
          ],
          "description": "Custom types only, and required there: the type's name. An extended built-in type has the registry's name."
        },
        "hosts": {
          "type": "array",
          "items": {
            "enum": [
              "network",
              "track",
              "waypoint",
              "highlight",
              "plan",
              "area"
            ]
          },
          "description": "Custom types only: the item kinds the type is meant for. Viatrail does not check it on import. \"waypoint\" means a VNX point, top-level or in a network."
        },
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/datatype-field"
          }
        },
        "summary": {
          "type": "string",
          "description": "A template for a one-line summary of a record. A fault drops the summary, not the type."
        },
        "strings": {
          "type": "object",
          "description": "Phrases a summary can use: phrase key, then language, then a text or a text for each plural form. English is required, and a plural table needs every form the language uses.",
          "additionalProperties": {
            "type": "object",
            "required": [
              "en"
            ],
            "propertyNames": {
              "pattern": "^[a-z]{2,3}$"
            },
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string",
                  "pattern": "\\S"
                },
                {
                  "type": "object",
                  "propertyNames": {
                    "enum": [
                      "zero",
                      "one",
                      "two",
                      "few",
                      "many",
                      "other"
                    ]
                  },
                  "additionalProperties": {
                    "type": "string",
                    "pattern": "\\S"
                  },
                  "required": [
                    "other"
                  ]
                }
              ]
            }
          }
        },
        "behaviours": {
          "type": "array",
          "items": {
            "enum": [
              "plan",
              "list",
              "camp"
            ]
          },
          "description": "Custom types only. plan: a highlight with a record of the type can start a plan along its line. list: the network lists the records of the type on its highlights. camp: a point with a record of the type can end a day of a plan."
        },
        "marker": {
          "allOf": [
            {
              "type": "object",
              "required": [
                "icon",
                "hue"
              ],
              "additionalProperties": false,
              "properties": {
                "icon": {
                  "type": "string",
                  "pattern": "^(lucide|emoji):.+$",
                  "description": "An icon: \"lucide:<id>\" for a Lucide icon or \"emoji:<id>\" for an emoji. An id the app does not have is dropped with a report."
                },
                "hue": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 359
                }
              }
            }
          ],
          "description": "Custom types only: the type's icon and hue. Absent: lucide:shapes at hue 0. An unusable value is removed with a report, and the type then has that default."
        }
      },
      "if": {
        "properties": {
          "datatype": {
            "enum": [
              "app.viatrail.camp",
              "app.viatrail.shelter",
              "app.viatrail.hotel",
              "app.viatrail.shop",
              "app.viatrail.settlement",
              "app.viatrail.water",
              "app.viatrail.note",
              "app.viatrail.route",
              "app.viatrail.terrain",
              "app.viatrail.hazard"
            ]
          }
        }
      },
      "then": {
        "not": {
          "anyOf": [
            {
              "required": [
                "label"
              ]
            },
            {
              "required": [
                "hosts"
              ]
            }
          ]
        }
      }
    },
    "datatype-field": {
      "type": "object",
      "required": [
        "name",
        "kind"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z0-9_]+$",
          "description": "The key in the record body."
        },
        "kind": {
          "enum": [
            "text",
            "markdown",
            "bool",
            "number",
            "integer",
            "stars",
            "enum",
            "date"
          ]
        },
        "label": {
          "allOf": [
            {
              "$ref": "#/$defs/label-map"
            }
          ],
          "description": "Required, except on a field the extended built-in type already has."
        },
        "note": {
          "$ref": "#/$defs/label-map"
        },
        "options": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/datatype-option"
          },
          "description": "The values of an enum field. Kept but not used on a field of another kind."
        }
      }
    },
    "datatype-option": {
      "type": "object",
      "required": [
        "value"
      ],
      "properties": {
        "value": {
          "type": "string",
          "pattern": "^[a-z0-9_]+$"
        },
        "label": {
          "allOf": [
            {
              "$ref": "#/$defs/label-map"
            }
          ],
          "description": "Required, except on an option the extended built-in field already has."
        },
        "note": {
          "$ref": "#/$defs/label-map"
        }
      }
    },
    "label-map": {
      "type": "object",
      "description": "Text by language: each key a lowercase primary language subtag (en, fr). English is required. A text may not be blank.",
      "propertyNames": {
        "pattern": "^[a-z]{2,3}$"
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "\\S"
      },
      "required": [
        "en"
      ]
    },
    "app.viatrail.rulesets": {
      "title": "Rule sets",
      "description": "Rule sets style the map. A rule set applies to the folder it is in and every folder below it. Viatrail never writes an empty list.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/ruleset"
      }
    },
    "ruleset": {
      "type": "object",
      "required": [
        "name",
        "enabled"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        },
        "folder": {
          "type": "string",
          "description": "The id of a folder in the same document. Absent or empty: the import places it where the user chooses. A folder the document does not have drops the rule set with a report."
        },
        "rules": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/rule"
          }
        },
        "pinned": {
          "type": "string",
          "description": "When the rule set was pinned: a VNX timestamp (§4.3)."
        }
      }
    },
    "rule": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "item-types": {
          "type": "array",
          "items": {
            "enum": [
              "waypoint",
              "plan",
              "track",
              "highlight",
              "area",
              "network"
            ]
          },
          "uniqueItems": true,
          "description": "The kinds of item the rule matches. An empty list matches nothing. \"waypoint\" means a VNX point, top-level or in a network."
        },
        "match-any": {
          "type": "boolean",
          "description": "True: an item matches when any condition holds. Absent or false: all must hold."
        },
        "conditions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/condition"
          }
        },
        "style": {
          "type": "array",
          "description": "The rule's style: its style records, each an object with its @type, at most one of each type.",
          "items": {
            "oneOf": [
              {
                "$ref": "#/$defs/app.viatrail.style.line"
              },
              {
                "$ref": "#/$defs/app.viatrail.style.fill"
              },
              {
                "$ref": "#/$defs/app.viatrail.style.card"
              },
              {
                "$ref": "#/$defs/app.viatrail.style.marker.item"
              },
              {
                "$ref": "#/$defs/app.viatrail.style.marker.data"
              }
            ]
          }
        },
        "behaviour": {
          "$ref": "#/$defs/app.viatrail.behaviour"
        }
      }
    },
    "condition": {
      "type": "object",
      "description": "A condition the app does not know (field or operator) is kept with a report and never matches.",
      "required": [
        "field",
        "operator"
      ],
      "properties": {
        "field": {
          "enum": [
            "name",
            "text",
            "folder",
            "path",
            "tag",
            "data"
          ],
          "description": "What the condition tests: one of the item's texts, or (data) its data records."
        },
        "operator": {
          "type": "string"
        },
        "value": {
          "type": "string",
          "description": "A text condition's text. A data condition has none."
        },
        "type": {
          "type": "string",
          "description": "A data condition's data type: any @type, built-in, custom or undefined."
        },
        "data-field": {
          "type": "string",
          "description": "A data condition's field, for an operator that tests a field."
        },
        "operand": {
          "description": "A data condition's value; its shape is the operator's (x-data-operators)."
        }
      },
      "oneOf": [
        {
          "title": "Text condition",
          "properties": {
            "field": {
              "enum": [
                "name",
                "text",
                "folder",
                "path",
                "tag"
              ]
            },
            "operator": {
              "enum": [
                "contains",
                "starts_with",
                "matches_regex"
              ]
            }
          },
          "not": {
            "anyOf": [
              {
                "required": [
                  "type"
                ]
              },
              {
                "required": [
                  "data-field"
                ]
              },
              {
                "required": [
                  "operand"
                ]
              }
            ]
          }
        },
        {
          "title": "Data condition",
          "required": [
            "type"
          ],
          "properties": {
            "field": {
              "const": "data"
            },
            "operator": {
              "enum": [
                "present",
                "absent",
                "contains",
                "starts_with",
                "matches_regex",
                "set",
                "unset",
                "is_true",
                "is_false",
                "eq",
                "ne",
                "lt",
                "le",
                "gt",
                "ge",
                "is",
                "is_not",
                "one_of",
                "before",
                "after"
              ]
            }
          },
          "not": {
            "required": [
              "value"
            ]
          },
          "allOf": [
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "present"
                  }
                }
              },
              "then": {
                "not": {
                  "anyOf": [
                    {
                      "required": [
                        "data-field"
                      ]
                    },
                    {
                      "required": [
                        "operand"
                      ]
                    }
                  ]
                }
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "absent"
                  }
                }
              },
              "then": {
                "not": {
                  "anyOf": [
                    {
                      "required": [
                        "data-field"
                      ]
                    },
                    {
                      "required": [
                        "operand"
                      ]
                    }
                  ]
                }
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "contains"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "string"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "starts_with"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "string"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "matches_regex"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "string"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "set"
                  }
                }
              },
              "then": {
                "not": {
                  "required": [
                    "operand"
                  ]
                },
                "required": [
                  "data-field"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "unset"
                  }
                }
              },
              "then": {
                "not": {
                  "required": [
                    "operand"
                  ]
                },
                "required": [
                  "data-field"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "is_true"
                  }
                }
              },
              "then": {
                "not": {
                  "required": [
                    "operand"
                  ]
                },
                "required": [
                  "data-field"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "is_false"
                  }
                }
              },
              "then": {
                "not": {
                  "required": [
                    "operand"
                  ]
                },
                "required": [
                  "data-field"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "eq"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "number"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "ne"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "number"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "lt"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "number"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "le"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "number"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "gt"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "number"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "ge"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "number"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "is"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "string"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "is_not"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "string"
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "one_of"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "before"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "string",
                    "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
                    "description": "A calendar day, YYYY-MM-DD."
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "const": "after"
                  }
                }
              },
              "then": {
                "properties": {
                  "operand": {
                    "type": "string",
                    "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
                    "description": "A calendar day, YYYY-MM-DD."
                  }
                },
                "required": [
                  "data-field",
                  "operand"
                ]
              }
            }
          ]
        }
      ],
      "x-data-operators": [
        {
          "operator": "present",
          "operand": "none",
          "takes-field": false
        },
        {
          "operator": "absent",
          "operand": "none",
          "takes-field": false
        },
        {
          "operator": "contains",
          "operand": "string",
          "takes-field": true
        },
        {
          "operator": "starts_with",
          "operand": "string",
          "takes-field": true
        },
        {
          "operator": "matches_regex",
          "operand": "string",
          "takes-field": true
        },
        {
          "operator": "set",
          "operand": "none",
          "takes-field": true
        },
        {
          "operator": "unset",
          "operand": "none",
          "takes-field": true
        },
        {
          "operator": "is_true",
          "operand": "none",
          "takes-field": true
        },
        {
          "operator": "is_false",
          "operand": "none",
          "takes-field": true
        },
        {
          "operator": "eq",
          "operand": "number",
          "takes-field": true
        },
        {
          "operator": "ne",
          "operand": "number",
          "takes-field": true
        },
        {
          "operator": "lt",
          "operand": "number",
          "takes-field": true
        },
        {
          "operator": "le",
          "operand": "number",
          "takes-field": true
        },
        {
          "operator": "gt",
          "operand": "number",
          "takes-field": true
        },
        {
          "operator": "ge",
          "operand": "number",
          "takes-field": true
        },
        {
          "operator": "is",
          "operand": "string",
          "takes-field": true
        },
        {
          "operator": "is_not",
          "operand": "string",
          "takes-field": true
        },
        {
          "operator": "one_of",
          "operand": "string-list",
          "takes-field": true
        },
        {
          "operator": "before",
          "operand": "date",
          "takes-field": true
        },
        {
          "operator": "after",
          "operand": "date",
          "takes-field": true
        }
      ]
    }
  }
}
