import "server-only";

/**
 * Appwrite SDK returns row objects that carry a non-plain prototype with
 * helpers like `toString`. Next.js's server-to-client serializer rejects
 * those. Use this helper to flatten any row (or row array) into a plain
 * object before crossing the boundary or returning from a server fn.
 *
 * JSON-roundtripping is deliberate: cheap, deterministic, drops every
 * non-serialisable field. Anything that needs to survive (Dates, Buffers)
 * has to be converted explicitly by the caller anyway.
 */
export function toPlain<T>(value: T): T {
  return JSON.parse(JSON.stringify(value)) as T;
}
