/**
 * Safe File constructor utility for use in Zod schemas
 * 
 * This utility provides a File constructor that works in both browser and Node.js environments.
 * In the browser, it uses the native File constructor.
 * In Node.js (server-side), it uses a fallback class to prevent "File is not defined" errors.
 * 
 * Usage in Zod schemas:
 * ```ts
 * import { SafeFileCtor } from "@/utils/safeFile";
 * 
 * const schema = z.object({
 *   file: z.instanceof(SafeFileCtor).optional(),
 * });
 * ```
 */

// Guarded File constructor for environments where File is not defined (e.g. Node.js/SSR)
export const SafeFileCtor: typeof File | (new (...args: any[]) => any) =
  typeof File !== "undefined" ? File : (class {} as any);

/**
 * Type guard to check if a value is a File instance
 * Works in both browser and server environments
 */
export function isFile(value: any): value is File {
  return typeof File !== "undefined" && value instanceof File;
}

