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

const episodes = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/episodes' }),
  schema: z.object({
    title: z.string(),
    season: z.number(),
    episode: z.number(),
    pubDate: z.coerce.date(),
    duration: z.string(),
    audioUrl: z.string().url(),
    audioSize: z.number(),
    episodeType: z.enum(['full', 'trailer', 'bonus']).default('full'),
    originalUrl: z.string().url().optional(),
    featured: z.boolean().default(false),
    classic: z.boolean().default(false),
    tags: z.array(z.string()).default([]),
    chapters: z.array(z.object({
      time: z.string(),
      title: z.string(),
    })).optional(),
  }),
});

const blog = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
  schema: z.object({
    title: z.string(),
    pubDate: z.coerce.date(),
    description: z.string(),
    author: z.string().default('Mike Swanson'),
    tags: z.array(z.string()).default([]),
    image: z.string().optional(),
    draft: z.boolean().default(false),
  }),
});

export const collections = { episodes, blog };
