// ── Content collections — typed frontmatter validation for projects and logs. ──
// Any md file that breaks the schema fails the build with a precise error.
// Add new enum values here (not in the content files).

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

const projects = defineCollection({
  loader: glob({ pattern: '*.md', base: './src/content/projects' }),
  schema: z.object({
    title: z.string(),
    tagline: z.string(), // one sentence, used on cards and meta description
    type: z.enum(['research', 'systems', 'hardware', 'hobby']),
    status: z.enum(['active', 'hibernating', 'archived']),
    /** Vocabulary: see AUTHORSHIP_LABELS in src/config.ts. Omit for none. */
    authorship: z.string().optional(),
    /** Featured cards get an accent border and homepage priority. */
    featured: z.boolean().default(false),
    /** Sort position on lists (lower first). */
    order: z.number().default(99),
    stack: z.array(z.string()).default([]),
    links: z
      .object({
        repo: z.string().optional(),
        live: z.string().optional(),
        demo: z.string().optional(),
        writeup: z.string().optional(),
      })
      .default({}),
    /** Built-in interactive component to mount on this project's page.
     *  See GUIDE.md §6 "Islands". */
    demoIsland: z.enum(['ntt', 'receipt']).optional(),
    /** Extra note line rendered under the links ("Coming to the lab soon"). */
    note: z.string().optional(),
  }),
});

const logs = defineCollection({
  loader: glob({ pattern: '*.md', base: './src/content/logs' }),
  schema: z.object({
    title: z.string(),
    /** One line for list rows, link previews and RSS. Optional. */
    description: z.string().optional(),
    pubDate: z.coerce.date(),
    tags: z.array(z.string()).default([]),
    /** Draft = hidden in production, visible in dev and build:drafts. */
    draft: z.boolean().default(false),
  }),
});

export const collections = { projects, logs };
