import { z } from "zod";

// Ensure image is optional but if provided it must be a File object
export const projectSchema = z.object({
  title: z.string().min(3, "Title must be at least 3 characters long"),
  slug: z.string().min(3, "Slug must be at least 3 characters long").regex(/^[a-z0-9-]+$/, "Slug must only contain lowercase letters, numbers, and dashes"),
  description: z.string().min(10, "Description must be at least 10 characters long"),
  category: z.string().min(1, "Category is required"),
  repoUrl: z.union([z.string().url("Must be a valid URL"), z.literal("")]).optional(),
  liveUrl: z.union([z.string().url("Must be a valid URL"), z.literal("")]).optional(),
  isPublished: z.boolean().default(false),
  // Validation for image handles Server ActionFormData natively
  image: z
    .any()
    .refine((file) => !file || file?.size === 0 || file?.name, "Invalid file format")
    .optional(),
  techStack: z.string().optional(),
  year: z.coerce.number().optional(),
  highlights: z.string().optional(),
});

export type ProjectFormValues = z.infer<typeof projectSchema>;
