import { LexiconDoc } from "@atproto/lexicon";
import { PubLeafletPagesLinearDocument } from "./pages/LinearDocument";
import { PubLeafletPagesCanvasDocument } from "./pages";

export const PubLeafletContent: LexiconDoc = {
  lexicon: 1,
  id: "pub.leaflet.content",
  revision: 1,
  description: "A lexicon for long form rich media documents",
  defs: {
    main: {
      type: "object",
      description: "Content format for leaflet documents",
      required: ["pages"],
      properties: {
        pages: {
          type: "array",
          items: {
            type: "union",
            refs: [
              PubLeafletPagesLinearDocument.id,
              PubLeafletPagesCanvasDocument.id,
            ],
          },
        },
        blobPages: {
          type: "blob",
          accept: ["application/json"],
          maxSize: 5000000,
          description:
            "JSON-encoded array of pages. When the inline pages array would be too large to store on the PDS, the pages are uploaded as a blob and referenced here. When set, consumers MUST ignore `pages` and use the decoded blob contents as the page array; the inline `pages` field will be empty or a stub.",
        },
        blobs: {
          type: "array",
          description:
            "Blobs referenced inside `blobPages`. Load-bearing when `blobPages` is set: the PDS only scans the top level of a record for blob references when deciding what to garbage-collect, so any image/etc. blob now living inside the opaque JSON blob must be mirrored here to remain referenced.",
          items: {
            type: "blob",
            accept: ["*/*"],
            maxSize: 10000000,
          },
        },
      },
    },
  },
};
