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

const news = defineCollection({
    loader: glob({
        pattern: "**/*.md",
        base: "./src/content/news",
        generateId: ({ data, entry }) => `${data.locale}/${data.slug ?? entry.replace(/\.md$/, "")}`,
    }),
    schema: ({ image }) => z.object({
        locale: z.string().describe("News main language"),
        title: z.string(),
        slug: z.string(),
        date: z.date(),
        draft: z.boolean().optional(),
        place: z.string().optional(),
        order: z.number().optional(),
        city: z.string().optional(),
        state: z.string().optional(),
        country: z.string().optional(),
        thumbnail: image().optional().describe("Main news thumbnail image"),
        thumbnail_square: image().optional().describe("Main news thumbnail square image"),
        youtube: z.string().optional(),
        tags: z.array(z.string()).optional().describe("News tags"),
        gallery: z.array(z.object({
            image: image().optional(),
            text: z.string().optional(),
            text_alt: z.string().optional(),
        })).optional().nullable()
    }),
});

const editorial = defineCollection({
    loader: glob({ pattern: "**/*.md", base: "./src/content/editorial" }),
    schema: ({ image }) => z.object({
        locale: z.string().describe("Editorial main language"),
        title: z.string(),
        slug: z.string(),
        date: z.date(),
        draft: z.boolean().optional(),
        place: z.string().optional(),
        order: z.number().optional(),
        city: z.string().optional(),
        state: z.string().optional(),
        country: z.string().optional(),
        thumbnail: image().optional().describe("Main editorial thumbnail image"),
        thumbnail_square: image().optional().describe("Main editorial thumbnail square image"),
        youtube: z.string().optional(),
        tags: z.array(z.string()).optional().describe("Editorial tags"),
        gallery: z.array(z.object({
            image: image().optional(),
            text: z.string().optional(),
            text_alt: z.string().optional(),
        })).optional().nullable()
    }),
});

export const collections = { news, editorial };