{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/interval-timer/backup-schema.json",
  "title": "Interval Timer backup",
  "description": "The file Interval Timer 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. Durations are whole seconds.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "timers", "sessions", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-interval-timer" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "timers": { "type": "array", "items": { "$ref": "#/$defs/timer" } },
    "sessions": { "type": "array", "items": { "$ref": "#/$defs/session" } },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "timer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "warmup", "cooldown", "rounds", "sets", "setRest", "skipLastRest", "notes", "steps"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 60 },
        "warmup": { "type": "integer", "minimum": 0, "maximum": 3600 },
        "cooldown": { "type": "integer", "minimum": 0, "maximum": 3600 },
        "rounds": { "type": "integer", "minimum": 1, "maximum": 99 },
        "sets": { "type": "integer", "minimum": 1, "maximum": 20 },
        "setRest": { "type": "integer", "minimum": 0, "maximum": 3600 },
        "skipLastRest": { "type": "boolean" },
        "notes": { "type": "string", "maxLength": 500 },
        "steps": { "type": "array", "minItems": 1, "maxItems": 50, "items": { "$ref": "#/$defs/step" } }
      }
    },
    "step": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "kind", "duration"],
      "properties": {
        "id": { "type": "string", "minLength": 1, "maxLength": 64 },
        "name": { "type": "string", "maxLength": 40 },
        "kind": { "enum": ["work", "rest"] },
        "duration": { "type": "integer", "minimum": 1, "maximum": 5999 }
      }
    },
    "session": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "timerId", "name", "day", "startedAt", "active", "planned", "done"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "timerId": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1, "maxLength": 60 },
        "day": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "startedAt": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,3})?Z$" },
        "active": { "type": "integer", "minimum": 0, "maximum": 86400 },
        "planned": { "type": "integer", "minimum": 1, "maximum": 14400 },
        "done": { "type": "boolean" }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "sound", "countdown", "finish", "volume", "vibrate", "flash", "wakeLock"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "sound": { "type": "boolean" },
        "countdown": { "type": "boolean" },
        "finish": { "type": "boolean" },
        "volume": { "type": "integer", "minimum": 0, "maximum": 100 },
        "vibrate": { "type": "boolean" },
        "flash": { "type": "boolean" },
        "wakeLock": { "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" }
      }
    }
  }
}
