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

const posts = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/posts' }),
  schema: z.object({
    title: z.string(),
    pubDate: z.coerce.date(),
    updatedDate: z.coerce.date().optional(),
    slug: z.string(),
    legacyId: z.union([z.string(), z.number()]).optional(),
    oldSlug: z.string().optional(),
    author: z.string().default('История города Пушкино'),
    categories: z.array(z.string()).default([]),
    categorySlugs: z.array(z.string()).default([]),
    tags: z.array(z.string()).default([]),
    description: z.string().default(''),
    featuredImage: z.string().optional(),
    featured: z.boolean().default(false),
    hideFromList: z.boolean().default(false),
  }),
});

const pages = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/pages' }),
  schema: z.object({
    title: z.string(),
    slug: z.string(),
    legacyId: z.union([z.string(), z.number()]).optional(),
    oldSlug: z.string().optional(),
    pubDate: z.coerce.date().optional(),
    updatedDate: z.coerce.date().optional(),
    description: z.string().default(''),
  }),
});

export const collections = { posts, pages };
