import { z } from 'zod';

// --- Author entry (for .authors.yml) ---

export const authorSocialLinkSchema = z.object({
  icon: z.string().min(1).max(100),
  link: z.string().url().max(500),
  name: z.string().max(100).optional(),
});

export const authorEntrySchema = z.object({
  name: z.string().min(1).max(100),
  description: z.string().max(500).optional(),
  avatar: z.string().max(500).optional(),
  social: z.array(authorSocialLinkSchema).max(10).optional(),
});

export const authorsFileSchema = z.object({
  authors: z.record(z.string().min(1).max(50), authorEntrySchema),
});

export type AuthorEntry = z.infer<typeof authorEntrySchema>;
export type AuthorsFile = z.infer<typeof authorsFileSchema>;

// --- Blog post frontmatter ---

export const blogFrontmatterSchema = z.object({
  date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Must be YYYY-MM-DD format'),
  authors: z.array(z.string().min(1)).min(1),
  categories: z.array(z.string().min(1)).default([]),
  tags: z.array(z.string().min(1)).optional(),
  draft: z.boolean().optional(),
  slug: z.string().regex(/^[a-z0-9-]+$/).max(200).optional(),
  description: z.string().max(500).optional(),
});

export type BlogFrontmatter = z.infer<typeof blogFrontmatterSchema>;

// --- New blog post wizard ---

export const newBlogPostSchema = z.object({
  title: z.string().min(1).max(200),
  date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
  authors: z.array(z.string()).min(1),
  categories: z.array(z.string()).default([]),
  draft: z.boolean().default(true),
  slug: z.string().regex(/^[a-z0-9-]+$/).max(200).optional(),
  description: z.string().max(500).optional(),
});

export type NewBlogPost = z.infer<typeof newBlogPostSchema>;
