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

const baseContentSchema = z.object({
    title: z.string(),
    description: z.string(),
    publishedAt: z.coerce.date().optional(),
});

const changelogSchema = baseContentSchema.extend({
    draft: z.boolean().default(false),
    publishedAt: z.coerce.date(),
});

const optionalContentSchema = baseContentSchema.extend({
    draft: z.boolean().default(false),
});

const editorialInventorySchema = baseContentSchema.extend({
    draft: z.boolean().default(true),
});

export const collections = {
    articles: defineCollection({
        loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/articles' }),
        schema: editorialInventorySchema,
    }),
    changelog: defineCollection({
        loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/changelog' }),
        schema: changelogSchema,
    }),
    resources: defineCollection({
        loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/resources' }),
        schema: optionalContentSchema,
    }),
};
