import { auth } from '@/lib/auth';
import { db } from '@/lib/db';
import { formTemplates } from '@/lib/db/schema';
import { asc } from 'drizzle-orm';

export async function GET() {
  const session = await auth();
  if (!session) return new Response('Unauthorized', { status: 401 });

  const forms = await db
    .select({ id: formTemplates.id, name: formTemplates.name, filename: formTemplates.filename })
    .from(formTemplates)
    .orderBy(asc(formTemplates.name));

  return Response.json(forms);
}
