{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "main": {
      "description": "Get the authenticated user's personal ebook library.",
      "output": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "books": {
              "items": {
                "ref": "#personalBookView",
                "type": "ref"
              },
              "type": "array"
            },
            "cursor": {
              "description": "Pagination cursor for the next page",
              "type": "string"
            },
            "storage": {
              "description": "This user's storage usage against their quota",
              "ref": "#storageView",
              "type": "ref"
            },
            "total": {
              "description": "Total number of books matching the query, across all pages",
              "type": "integer"
            }
          },
          "required": [
            "books"
          ],
          "type": "object"
        }
      },
      "parameters": {
        "properties": {
          "cursor": {
            "description": "Pagination cursor",
            "type": "string"
          },
          "limit": {
            "default": 24,
            "description": "Maximum number of books to return",
            "maximum": 100,
            "minimum": 1,
            "type": "integer"
          },
          "q": {
            "description": "Case-insensitive substring match against title or authors. Mirrors the OPDS search feed.",
            "maxLength": 256,
            "minLength": 1,
            "type": "string"
          },
          "shelfId": {
            "description": "Filter by personal shelf ID",
            "type": "integer"
          },
          "sort": {
            "default": "recent",
            "description": "Result ordering. `recent` is newest-added first (the default, matching the library page and the OPDS /all feed); `title` and `author` are ascending alphabetical, matching the OPDS search results feed. Not switched implicitly when `q` is set — pass it explicitly.",
            "knownValues": [
              "recent",
              "title",
              "author"
            ],
            "type": "string"
          }
        },
        "type": "params"
      },
      "type": "query"
    },
    "personalBookView": {
      "properties": {
        "authors": {
          "description": "Authors of the book (tab-separated)",
          "type": "string"
        },
        "contentHash": {
          "description": "SHA-256 hash of the file content, used as stable identifier",
          "type": "string"
        },
        "coverUrl": {
          "description": "URL of the book cover image. When it points at the public catalog image proxy it needs no authentication; the `/library/covers/...` form is session-authenticated, so a client using service auth should use `hasLocalCover` and getPersonalBookCover instead.",
          "type": "string"
        },
        "createdAt": {
          "description": "When the book was added to the library",
          "format": "datetime",
          "type": "string"
        },
        "description": {
          "description": "Synopsis from the linked BookHive catalog entry. Deliberately unbounded: this is scraped catalog copy, not user input, and 125 of the 367k descriptions in production already exceed 5000 bytes (longest 10386). A maxLength here would be a contract the data violates, and enforcing it would mean truncating a synopsis mid-sentence.",
          "type": "string"
        },
        "filename": {
          "description": "Original uploaded file name. A sync client needs this to correlate the book with what is on the device.",
          "type": "string"
        },
        "format": {
          "description": "File format (e.g. epub, pdf, mobi, fb2, cbz)",
          "type": "string"
        },
        "hasLocalCover": {
          "description": "Whether a cover extracted from the uploaded file is stored. Fetch it with getPersonalBookCover, which works under any supported authentication.",
          "type": "boolean"
        },
        "hiveId": {
          "description": "Linked BookHive catalog entry ID",
          "type": "string"
        },
        "language": {
          "description": "Language of the book",
          "type": "string"
        },
        "mime": {
          "description": "MIME type of the file",
          "type": "string"
        },
        "progress": {
          "description": "E-reader reading progress, when this book has been synced",
          "ref": "#syncProgressView",
          "type": "ref"
        },
        "shelfIds": {
          "description": "IDs of the personal shelves this book belongs to",
          "items": {
            "type": "integer"
          },
          "type": "array"
        },
        "sizeBytes": {
          "description": "File size in bytes",
          "type": "integer"
        },
        "title": {
          "description": "Title of the book",
          "type": "string"
        },
        "updatedAt": {
          "description": "When the book record was last updated",
          "format": "datetime",
          "type": "string"
        }
      },
      "required": [
        "contentHash",
        "title",
        "format",
        "mime",
        "sizeBytes",
        "createdAt",
        "updatedAt"
      ],
      "type": "object"
    },
    "storageView": {
      "properties": {
        "quotaBytes": {
          "description": "Total bytes this user is allowed to store",
          "minimum": 0,
          "type": "integer"
        },
        "usedBytes": {
          "description": "Total bytes currently stored for this user",
          "minimum": 0,
          "type": "integer"
        }
      },
      "required": [
        "usedBytes",
        "quotaBytes"
      ],
      "type": "object"
    },
    "syncProgressView": {
      "properties": {
        "device": {
          "description": "Name of the device that last reported progress",
          "type": "string"
        },
        "percentage": {
          "description": "Reading progress as a fraction between 0 and 1",
          "type": "string"
        },
        "updatedAt": {
          "description": "When progress was last synced",
          "format": "datetime",
          "type": "string"
        }
      },
      "required": [
        "percentage",
        "updatedAt"
      ],
      "type": "object"
    }
  },
  "id": "buzz.bookhive.getPersonalLibrary",
  "lexicon": 1
}
