/**
 * Database Client — Convex-backed Prisma Compatibility Adapter
 *
 * This module replaces the original Prisma Client singleton with a Convex-backed
 * proxy. Existing API routes continue to import `prisma` from `@/lib/db` and call
 * methods like `prisma.users.findUnique(...)`, but those calls are routed to
 * Convex queries and mutations under the hood.
 *
 * See `lib/prisma-convex-adapter.ts` for the full implementation.
 */

import { buildConvexPrismaProxy } from "./prisma-convex-adapter";

const globalForProxy = global as unknown as {
  prisma: ReturnType<typeof buildConvexPrismaProxy>;
};

export const prisma = globalForProxy.prisma || buildConvexPrismaProxy();

// Export as default for backward compatibility with existing routes
export default prisma;

if (process.env.NODE_ENV !== "production") {
  globalForProxy.prisma = prisma;
}
