import { defineCollection, z } from "astro:content";

/**
 * Shared SEO/AEO frontmatter rules (ADR-0003). Encoded as Zod so violations FAIL the build:
 * `astro check` / `astro build` reject any content entry that breaks these constraints.
 * See docs/seo-aeo-optimization.md §1.
 */
export const seoSchema = z.object({
  // Rendered as "`title` | BlueCap Strategies"; keep the base title tight so the full SERP title
  // stays within ~60 chars where practical.
  title: z.string().min(3).max(60),
  // Serves as <meta name="description"> + OG/Twitter description; 120–158 is the safe SERP / AI
  // snippet window.
  description: z.string().min(120).max(158),
  // Canonical is derived from the route by default; override only for cross-posted content.
  canonicalUrl: z.string().url().optional(),
  // Absolute path to a social share image under /assets (falls back to the layout default).
  ogImage: z.string().startsWith("/assets/").optional(),
  // Primary entity/topic — powers internal linking and schema keywords.
  primaryTopic: z.string().optional(),
  noindex: z.boolean().default(false),
});

/**
 * Service + focus-area detail pages (ADR-0002). Prose lives in the Markdown body (exact live-site
 * copy — see docs/live-site-content-inventory.md); structured/SEO fields live in frontmatter.
 * `summary` is the exact overview paragraph reused on the /services/, /focus-areas/, and homepage
 * cards; `description` is the SEO meta description.
 */
const detailSchema = seoSchema.extend({
  summary: z.string().min(1),
  eyebrow: z.string(),
  lead: z.string().optional(),
  order: z.number(),
  icon: z.string().optional(),
  image: z.string().optional(),
});

const insights = defineCollection({
  type: "content",
  schema: seoSchema.extend({
    publishDate: z.date(),
    modifiedDate: z.date().optional(),
    tags: z.array(z.string()).default([]),
    draft: z.boolean().default(false),
  }),
});

const services = defineCollection({ type: "content", schema: detailSchema });
const focusAreas = defineCollection({ type: "content", schema: detailSchema });

// Standalone long-form pages (About, etc.) — prose in the Markdown body (ADR-0002), hero + SEO
// fields in frontmatter. The sticky in-page nav is derived from the body's h2 headings.
const pages = defineCollection({
  type: "content",
  schema: seoSchema.extend({
    eyebrow: z.string().optional(),
    heroTitle: z.string(),
    heroLead: z.string().optional(),
    heroImage: z.string().optional(),
    heroImageAlt: z.string().optional(),
  }),
});

export const collections = { insights, services, "focus-areas": focusAreas, pages };
