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

export const PubLeafletDocument: LexiconDoc = {
  lexicon: 1,
  id: "pub.leaflet.document",
  revision: 1,
  description: "A lexicon for long form rich media documents",
  defs: {
    main: {
      type: "record",
      key: "tid",
      description: "Record containing a document",
      record: {
        type: "object",
        required: ["pages", "author", "title"],
        properties: {
          title: { type: "string", maxLength: 5000, maxGraphemes: 500 },
          postRef: { type: "ref", ref: "com.atproto.repo.strongRef" },
          description: { type: "string", maxLength: 30000, maxGraphemes: 3000 },
          publishedAt: { type: "string", format: "datetime" },
          publication: { type: "string", format: "at-uri" },
          author: { type: "string", format: "at-identifier" },
          theme: { type: "ref", ref: "pub.leaflet.publication#theme" },
          preferences: {
            type: "ref",
            ref: "pub.leaflet.publication#preferences",
          },
          tags: { type: "array", items: { type: "string", maxLength: 50 } },
          coverImage: {
            type: "blob",
            accept: ["image/png", "image/jpeg", "image/webp"],
            maxSize: 1000000,
          },
          pages: {
            type: "array",
            items: {
              type: "union",
              refs: [
                PubLeafletPagesLinearDocument.id,
                PubLeafletPagesCanvasDocument.id,
              ],
            },
          },
        },
      },
    },
  },
};
