{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://lunelet.com/schema.json",
  "title": "Lunelet public reading shelf",
  "type": "object",
  "required": [
    "schemaVersion",
    "revision",
    "name",
    "updatedAt",
    "books"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "revision": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740990
    },
    "name": {
      "type": "string",
      "maxLength": 120
    },
    "updatedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "books": {
      "type": "array",
      "maxItems": 2000,
      "items": {
        "$ref": "#/$defs/Book"
      }
    }
  },
  "$defs": {
    "Book": {
      "allOf": [
        {
          "$ref": "#/$defs/BookInput"
        },
        {
          "type": "object",
          "required": [
            "id",
            "status"
          ],
          "properties": {
            "id": {
              "type": "string",
              "maxLength": 80,
              "minLength": 1,
              "pattern": "\\S"
            },
            "status": {
              "enum": [
                "reading",
                "finished"
              ]
            }
          }
        }
      ]
    },
    "BookInput": {
      "type": "object",
      "required": [
        "title",
        "author"
      ],
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        "author": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        "workId": {
          "type": "string",
          "pattern": "^(OL[0-9]+W)?$",
          "description": "Open Library work ID (not an edition ID). Empty when unknown."
        },
        "cover": {
          "type": "string",
          "maxLength": 2048,
          "description": "HTTPS URL or root-relative path. Empty when unavailable."
        },
        "url": {
          "type": "string",
          "maxLength": 2048,
          "description": "HTTPS book link or root-relative path."
        },
        "startedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date",
          "description": "Null if the actual reading start date is unknown."
        },
        "finishedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "progress": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "note": {
          "type": "string",
          "maxLength": 280
        }
      }
    }
  }
}
