{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/people-notes/backup-schema.json",
  "title": "People Notes backup",
  "description": "The file People Notes 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.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "people", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-people-notes" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "people": { "type": "array", "items": { "$ref": "#/$defs/person" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "person": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "nickname", "howMet", "likes", "dislikes", "kids", "pets", "notes", "tags", "goal", "snoozeUntil", "created", "updated", "contacts"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "maxLength": 80 },
        "nickname": { "type": "string", "maxLength": 60 },
        "howMet": { "type": "string", "maxLength": 500 },
        "likes": { "type": "string", "maxLength": 1000 },
        "dislikes": { "type": "string", "maxLength": 1000 },
        "kids": { "type": "string", "maxLength": 1000 },
        "pets": { "type": "string", "maxLength": 1000 },
        "notes": { "type": "string", "maxLength": 5000 },
        "tags": { "type": "array", "maxItems": 8, "items": { "type": "string", "maxLength": 24 } },
        "goal": {
          "oneOf": [
            { "type": "null" },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["every", "unit"],
              "properties": {
                "every": { "type": "integer", "minimum": 1, "maximum": 365 },
                "unit": { "enum": ["days", "weeks", "months"] }
              }
            }
          ]
        },
        "snoozeUntil": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "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}$" },
        "contacts": { "type": "array", "items": { "$ref": "#/$defs/contact" } }
      }
    },
    "contact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "day", "type", "note"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "day": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "type": { "enum": ["call", "text", "visit", "video", "email", "letter", "other"] },
        "note": { "type": "string", "maxLength": 500 }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "sort"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "sort": { "enum": ["name", "recent", "due"] }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lastExport", "firstUse", "welcomed"],
      "properties": {
        "lastExport": { "type": ["string", "null"], "format": "date-time" },
        "firstUse": { "type": ["string", "null"], "format": "date-time" },
        "welcomed": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
