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 createWorkspaceSchema = z.object({
  name: z.string().trim().min(1, "Must be 1 or more characters"),
  image: z
    .union([
      fileSchema,
      z.string().transform((value: string) => (value === "" ? undefined : value)),
    ])
    .optional(),
});

export const updateWorkspaceSchema = z.object({
  name: z.string().trim().min(1, "Must be 1 or more characters").optional(),
  image: z
    .union([
      fileSchema,
      z.string().transform((value: string) => (value === "" ? undefined : value)),
    ])
    .optional(),
});
