import { glob } from "astro/loaders";
import { defineCollection, z } from "astro:content";

const blogSchema = z.object({
  title: z.string(),
  description: z.string(),
  pubDate: z.coerce.date(),
  updatedDate: z.coerce.date().optional(),
  image: z.string().optional(),
  authorImage: z.string().optional(),
  authorName: z.string().optional(),
  "main-feature": z.boolean().optional(),
  mainFeature: z.boolean().optional(),
});

const research = defineCollection({
  loader: glob({
    base: "./src/content/research",
    pattern: "**/*.{md,mdx}",
  }),
  schema: blogSchema,
});

const puzzles = defineCollection({
  loader: glob({
    base: "./src/content/puzzles",
    pattern: "**/*.{md,mdx}",
  }),
  schema: blogSchema,
});

const reviews = defineCollection({
  loader: glob({ base: "./src/content/reviews", pattern: "**/*.{md,mdx}" }),
  schema: blogSchema,
});

const reflections = defineCollection({
  loader: glob({ base: "./src/content/reflections", pattern: "**/*.{md,mdx}" }),
  schema: blogSchema,
});

const vibes = defineCollection({
  loader: glob({ base: "./src/content/vibes", pattern: "**/*.{md,mdx}" }),
  schema: blogSchema,
});

const art = defineCollection({
  loader: glob({ base: "./src/content/art", pattern: "**/*.{md,mdx}" }),
  schema: blogSchema,
});

const poetry = defineCollection({
  loader: glob({ base: "./src/content/poetry", pattern: "**/*.{md,mdx}" }),
  schema: blogSchema,
});

export const collections = {
  research,
  vibes,
  puzzles,
  reflections,
  poetry,
  reviews,
  art,
};
