import { z } from 'astro/zod';

export const postSchema = z.object({
title: z.string().trim().min(1),
description: z.string().trim().min(1),
date: z.iso.date(),
draft: z.boolean().default(false),
selected: z.boolean().default(false),
tags: z.array(z.string().trim().min(1)).default([]),
cover: z.string().regex(/^\/images\/(?:[a-z0-9-]+\/)*[a-z0-9-]+\.(?:webp|avif|png|jpe?g)$/,
'Use a local image URL such as /images/blog/my-post.webp').optional(),
coverAlt: z.string().trim().min(1).optional(),
legacyUrls: z.array(z.string().regex(/^\/(?:blog\/)?\d{4}\/\d{2}\/\d{2}\/[a-z0-9-]+\.html$/)).default([]),
}).refine(post => Boolean(post.cover) === Boolean(post.coverAlt), {
message: 'Provide both cover and coverAlt, or omit both for a text-only post.',
path: ['coverAlt'],
