{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/event-planner/backup-schema.json",
  "title": "Event Planner backup",
  "description": "The file Event 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. Dates are YYYY-MM-DD; times are minutes after midnight.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "events", "templates", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-event-planner" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "events": { "type": "array", "maxItems": 300, "items": { "$ref": "#/$defs/event" } },
    "templates": { "type": "array", "maxItems": 50, "items": { "$ref": "#/$defs/template" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "day", "time", "location", "notes", "status", "planFor", "created", "updated", "guests", "tasks", "supplies", "slots"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "day": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "time": { "type": ["integer", "null"], "minimum": 0, "maximum": 1439 },
        "location": { "type": "string", "maxLength": 200 },
        "notes": { "type": "string", "maxLength": 4000 },
        "status": { "enum": ["planning", "done"] },
        "planFor": { "enum": ["yes", "yesMaybe", "all"] },
        "created": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "updated": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "guests": { "type": "array", "maxItems": 500, "items": { "$ref": "#/$defs/guest" } },
        "tasks": { "type": "array", "maxItems": 200, "items": { "$ref": "#/$defs/task" } },
        "supplies": { "type": "array", "maxItems": 300, "items": { "$ref": "#/$defs/supply" } },
        "slots": { "type": "array", "maxItems": 100, "items": { "$ref": "#/$defs/slot" } }
      }
    },
    "guest": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "adults", "kids", "plusOnes", "rsvp", "dietary", "notes"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "adults": { "type": "integer", "minimum": 0, "maximum": 50 },
        "kids": { "type": "integer", "minimum": 0, "maximum": 50 },
        "plusOnes": { "type": "integer", "minimum": 0, "maximum": 20 },
        "rsvp": { "enum": ["yes", "maybe", "invited", "no"] },
        "dietary": { "type": "string", "maxLength": 200 },
        "notes": { "type": "string", "maxLength": 1000 }
      }
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "offset", "day", "done"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "title": { "type": "string", "minLength": 1, "maxLength": 120 },
        "offset": { "type": ["integer", "null"], "minimum": -365, "maximum": 60 },
        "day": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "done": { "type": "boolean" }
      }
    },
    "supply": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "item", "category", "qty", "rule", "by", "got"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "item": { "type": "string", "minLength": 1, "maxLength": 120 },
        "category": { "enum": ["food", "drinks", "tableware", "decor", "activities", "other"] },
        "qty": { "type": "integer", "minimum": 0, "maximum": 9999 },
        "rule": {
          "oneOf": [
            { "type": "null" },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["amount", "per"],
              "properties": {
                "amount": { "type": "integer", "minimum": 1, "maximum": 50 },
                "per": { "type": "integer", "minimum": 1, "maximum": 50 }
              }
            }
          ]
        },
        "by": { "type": ["string", "null"] },
        "got": { "type": "boolean" }
      }
    },
    "slot": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "time", "title", "notes"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "time": { "type": "integer", "minimum": 0, "maximum": 1439 },
        "title": { "type": "string", "minLength": 1, "maxLength": 120 },
        "notes": { "type": "string", "maxLength": 1000 }
      }
    },
    "template": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "tasks"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "tasks": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "title", "offset"],
            "properties": {
              "id": { "type": "string", "minLength": 1, "maxLength": 64 },
              "title": { "type": "string", "minLength": 1, "maxLength": 120 },
              "offset": { "type": "integer", "minimum": -365, "maximum": 60 }
            }
          }
        }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lastExport", "firstUse"],
      "properties": {
        "lastExport": { "type": ["string", "null"], "format": "date-time" },
        "firstUse": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
