import { z } from "zod";

// Custom file validation that works during build
const fileSchema = z.custom<File>((value: unknown) => {
  // During build time, File might not be available, so we allow any object with File-like properties
  if (typeof File === 'undefined') {
    return value && typeof value === 'object' && value !== null;
  }
  return value instanceof File;
}, "Must be a valid file");

export const createProjectSchema = z.object({
  name: z.string().trim().min(1, "Required"),
  image: z
    .union([
      fileSchema,
      z.string().transform((value: string) => (value === "" ? undefined : value)),
    ])
    .optional(),

  workspaceId: z.string(),
});

export const updateProjectSchema = z.object({
  name: z.string().trim().min(1, "Minimum 1 character required").optional(),
  image: z
    .union([
      fileSchema,
      z.string().transform((value: string) => (value === "" ? undefined : value)),
    ])
    .optional(),
});
