import { NextRequest, NextResponse } from 'next/server' import { getServerSession } from 'next-auth' import { authOptions } from '@/lib/auth' import { prisma } from '@/lib/prisma' import { generateApiKey, slugify } from '@/lib/utils' export async function GET() { const session = await getServerSession(authOptions) if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) const clients = await prisma.client.findMany({ orderBy: { createdAt: 'desc' }, include: { _count: { select: { smsQueue: true, smsLogs: true } }, }, }) return NextResponse.json(clients) } export async function POST(req: NextRequest) { const session = await getServerSession(authOptions) if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) const body = await req.json() const { name, semaphoreKey, senderName } = body if (!name) return NextResponse.json({ error: 'Name is required' }, { status: 400 }) const slug = slugify(name) const apiKey = generateApiKey() const client = await prisma.client.create({ data: { name, slug, apiKey, semaphoreKey, senderName: senderName || 'NFC-HUB' }, }) return NextResponse.json(client, { status: 201 }) }