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: 1280, maxGraphemes: 128 },
          postRef: { type: "ref", ref: "com.atproto.repo.strongRef" },
          description: { type: "string", maxLength: 3000, maxGraphemes: 300 },
          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" },
          pages: {
            type: "array",
            items: {
              type: "union",
              refs: [
                PubLeafletPagesLinearDocument.id,
                PubLeafletPagesCanvasDocument.id,
              ],
            },
          },
        },
      },
    },
  },
};
