{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.fanettiai.com/software/reading-log/backup-schema.json",
  "title": "Reading Log backup",
  "description": "The file Reading 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. Dates are YYYY-MM-DD. A book's length is pages for print and e-books, minutes for audio. A session amount is pages or minutes depending on the book's format.",
  "type": "object",
  "additionalProperties": false,
  "required": ["app", "schemaVersion", "books", "sessions", "goals", "settings", "meta", "exportedAt", "appVersion"],
  "properties": {
    "app": { "const": "fanetti-reading-log" },
    "schemaVersion": { "type": "integer", "minimum": 1, "maximum": 1 },
    "books": { "type": "array", "items": { "$ref": "#/$defs/book" } },
    "sessions": { "type": "array", "items": { "$ref": "#/$defs/session" } },
    "goals": {
      "type": "object",
      "propertyNames": { "pattern": "^[0-9]{4}$" },
      "additionalProperties": { "$ref": "#/$defs/goal" }
    },
    "settings": { "$ref": "#/$defs/settings" },
    "meta": { "$ref": "#/$defs/meta" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "appVersion": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "book": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "author", "format", "length", "shelf", "rating", "tags", "series", "seriesNo", "favorite", "added", "started", "finished", "review", "quotes"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "maxLength": 200 },
        "author": { "type": "string", "maxLength": 120 },
        "format": { "enum": ["print", "ebook", "audio"] },
        "length": { "type": ["integer", "null"], "minimum": 1, "maximum": 20000 },
        "shelf": { "enum": ["reading", "want", "finished", "dnf"] },
        "rating": { "type": "number", "minimum": 0, "maximum": 5, "multipleOf": 0.5 },
        "tags": { "type": "array", "maxItems": 12, "items": { "type": "string", "maxLength": 30 } },
        "series": { "type": "string", "maxLength": 120 },
        "seriesNo": { "type": ["number", "null"], "minimum": 0, "maximum": 9999 },
        "favorite": { "type": "boolean" },
        "added": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "started": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "finished": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "review": { "type": "string", "maxLength": 4000 },
        "quotes": { "type": "array", "maxItems": 200, "items": { "$ref": "#/$defs/quote" } }
      }
    },
    "quote": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "text", "page", "added"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "text": { "type": "string", "maxLength": 1000 },
        "page": { "type": ["integer", "null"], "minimum": 0, "maximum": 20000 },
        "added": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }
      }
    },
    "session": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "bookId", "date", "amount", "note"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "bookId": { "type": "string", "minLength": 1 },
        "date": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "amount": { "type": "integer", "minimum": 1, "maximum": 2000 },
        "note": { "type": "string", "maxLength": 200 }
      }
    },
    "goal": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "target"],
      "properties": {
        "type": { "enum": ["books", "pages"] },
        "target": { "type": "integer", "minimum": 1, "maximum": 500000 },
        "sample": { "type": "boolean" }
      }
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["theme", "notifications", "defaultFormat", "weekStartsOn"],
      "properties": {
        "theme": { "enum": ["system", "light", "dark"] },
        "notifications": { "type": "boolean" },
        "defaultFormat": { "enum": ["print", "ebook", "audio"] },
        "weekStartsOn": { "enum": [0, 1] }
      }
    },
    "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" }
      }
    }
  }
}
