{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/trip-planner/backup-schema.json",
  "title": "Trip Planner backup",
  "description": "The file Trip Planner writes when you choose Download backup. Every value stays on your device; this schema documents the exact shape so the data stays readable without the app. Times are whole minutes after midnight in the trip's own time zone.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "trips", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-trip-planner" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "trips": { "type": "array", "maxItems": 100, "items": { "$ref": "#/$defs/trip" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "trip": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "destination", "start", "end", "zone", "notes", "items"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 120 },
        "destination": { "type": "string", "maxLength": 200 },
        "start": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "end": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "zone": { "type": "string", "minLength": 1 },
        "notes": { "type": "string", "maxLength": 4000 },
        "items": { "type": "array", "maxItems": 1000, "items": { "$ref": "#/$defs/item" } }
      }
    },
    "item": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "title", "date", "start", "end", "place", "ref", "notes", "order"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "type": { "enum": ["flight", "train", "drive", "stay", "activity", "food", "other"] },
        "title": { "type": "string", "minLength": 1, "maxLength": 200 },
        "date": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "start": { "type": ["integer", "null"], "minimum": 0, "maximum": 1439 },
        "end": { "type": ["integer", "null"], "minimum": 1, "maximum": 2879 },
        "place": { "type": "string", "maxLength": 300 },
        "ref": { "type": "string", "maxLength": 120 },
        "notes": { "type": "string", "maxLength": 4000 },
        "order": { "type": "integer" }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "activeTrip", "timeFormat"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "activeTrip": { "type": "string" },
        "timeFormat": { "enum": ["12h", "24h"] }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lastExport", "firstUse"],
      "properties": {
        "lastExport": { "type": ["string", "null"], "format": "date-time" },
        "firstUse": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
