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

const blogCollection = defineCollection({
  type: "content",
  schema: z.object({
    title: z.string(),
    excerpt: z.string(),
    author: z.object({
      name: z.string(),
      avatar: z.string(),
      role: z.string().optional(),
    }),
    publishDate: z.string().transform(str => new Date(str)), // Transform string to Date
    readTime: z.string().optional(),
    tags: z.array(z.string()).optional().default([]),
    featuredImage: z.string().optional(),
    tableOfContents: z.array(
      z.object({
        id: z.string(),
        title: z.string(),
      })
    ).optional().default([]),
  }),
});

export const collections = { blog: blogCollection };