import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';

let prismaPromise: Promise<any> | null = null;

async function getPrismaClient() {
  if (!prismaPromise) {
    prismaPromise = import('@prisma/client').then(({ PrismaClient }) => new PrismaClient());
  }
  return prismaPromise;
}

export const GET: RequestHandler = async () => {
  const prisma = await getPrismaClient(); // Hier Prisma Client holen
  const dienststellen = await prisma.dienststelle.findMany({ orderBy: { name: 'asc' } });
  return json(dienststellen);
};