{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/practice-log/backup-schema.json",
  "title": "Practice Log backup",
  "description": "The file Practice Log 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; tempos are whole BPM.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "skills", "items", "sessions", "timer", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-practice-log" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "skills": { "type": "array", "items": { "$ref": "#/$defs/skill" } },
    "items": { "type": "array", "items": { "$ref": "#/$defs/item" } },
    "sessions": { "type": "array", "items": { "$ref": "#/$defs/session" } },
    "timer": { "oneOf": [ { "type": "null" }, { "$ref": "#/$defs/timer" } ] },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "skill": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "color", "goal", "archived"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "color": { "enum": ["blue", "green", "orange", "purple", "teal", "red", "gold", "pink"] },
        "goal": { "type": "integer", "minimum": 0, "maximum": 10080 },
        "archived": { "type": "boolean" }
      }
    },
    "item": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "skillId", "name", "status", "target", "notes", "tempos"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "skillId": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1, "maxLength": 80 },
        "status": { "enum": ["learning", "polishing", "mastered"] },
        "target": { "type": ["integer", "null"], "minimum": 20, "maximum": 300 },
        "notes": { "type": "string", "maxLength": 4000 },
        "tempos": { "type": "array", "maxItems": 500, "items": { "$ref": "#/$defs/tempo" } }
      }
    },
    "tempo": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "day", "bpm", "note"],
      "properties": {
        "id": { "type": "string", "minLength": 1, "maxLength": 64 },
        "day": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "bpm": { "type": "integer", "minimum": 20, "maximum": 300 },
        "note": { "type": "string", "maxLength": 1000 }
      }
    },
    "session": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "skillId", "day", "start", "min", "parts", "focus", "notes", "via"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$" },
        "skillId": { "type": "string", "minLength": 1 },
        "day": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "start": { "type": ["integer", "null"], "minimum": 0, "maximum": 1439 },
        "min": { "type": "integer", "minimum": 1, "maximum": 1440 },
        "parts": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["itemId", "min"],
            "properties": {
              "itemId": { "type": "string", "minLength": 1 },
              "min": { "type": "integer", "minimum": 1, "maximum": 1440 }
            }
          }
        },
        "focus": { "type": ["integer", "null"], "minimum": 1, "maximum": 5 },
        "notes": { "type": "string", "maxLength": 4000 },
        "via": { "enum": ["timer", "manual"] }
      }
    },
    "timer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["skillId", "startedAt", "runningSince", "itemId", "acc"],
      "properties": {
        "skillId": { "type": "string", "minLength": 1 },
        "startedAt": { "type": "integer", "minimum": 946684800000, "maximum": 4102444800000 },
        "runningSince": { "type": ["integer", "null"], "minimum": 946684800000, "maximum": 4102444800000 },
        "itemId": { "type": ["string", "null"] },
        "acc": {
          "type": "object",
          "additionalProperties": { "type": "integer", "minimum": 1, "maximum": 604800000 }
        }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "weekStart", "metronome"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "weekStart": { "enum": [0, 1] },
        "metronome": {
          "type": "object",
          "additionalProperties": false,
          "required": ["bpm", "beats", "accent", "sound"],
          "properties": {
            "bpm": { "type": "integer", "minimum": 20, "maximum": 300 },
            "beats": { "type": "integer", "minimum": 1, "maximum": 12 },
            "accent": { "type": "boolean" },
            "sound": { "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" }
      }
    }
  }
}
