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

const defaultSchema = ({ image }: { image: ImageFunction }) =>
  z.object({
    title: z.string(),
    date: z.date(),
    cover: image().optional(),
    links: z.array(z.array(z.string())).optional(),
    rating: z.union([z.string(), z.number()]).optional(),
    coverAlt: z.string().optional(),
    toc: z.boolean().optional(),
    description: z.string().optional(),
    icon: z.string().optional(),
    author: z.string().optional(),
    draft: z.boolean().optional(),
    featured: z.boolean().optional(),
    tags: z.array(z.string()).optional(),
    _layout: z.enum(["normal", "transparent"]).optional(),
  });

export const collections = {
  "blog": defineCollection({
    loader: glob({ pattern: "**/[^_]*.{md,mdx}", base: "./src/content/blog" }),
    schema: defaultSchema,
  }),
  "projects": defineCollection({
    loader: glob({
      pattern: "**/[^_]*.{md,mdx}",
      base: "./src/content/projects",
    }),
    schema: defaultSchema,
  }),
  "photos": defineCollection({
    loader: glob({
      pattern: "**/[^_]*.{md,mdx}",
      base: "./src/content/photos",
    }),
    schema: defaultSchema,
  }),
};
