import { defineCollection } from "astro:content";
import { glob } from "astro/loaders";
import { z } from "astro/zod";

const common = z.object({
  title: z.string(),
  summary: z.string(),
  date: z.string(),
  updated: z.string(),
  topic: z.string(),
  tags: z.array(z.string()).default([]),
  status: z.enum(["draft", "published", "archived"]),
  visibility: z.literal("public"),
  canonicalUrl: z.url(),
  sourceRepo: z.url().optional(),
  preview: z.string().optional()
});

const posts = defineCollection({
  loader: glob({ pattern: "**/*.md", base: "./content/posts" }),
  schema: common.extend({ kind: z.literal("article") })
});

const sites = defineCollection({
  loader: glob({ pattern: "**/*.md", base: "./content/sites" }),
  schema: common.extend({ kind: z.literal("site") })
});

export const collections = { posts, sites };
