import { PrismaClient, Special } from '@prisma/client'; import { NextResponse } from 'next/server'; const prisma = new PrismaClient(); export async function GET() { const specials = await prisma.special.findMany({ orderBy: { name: 'asc' }, include: { _count: { select: { songs: true } } } }); return NextResponse.json(specials); } export async function POST(request: Request) { const { name, maxAttempts = 7, unlockSteps = '[2,4,7,11,16,30,60]', launchDate, endDate } = await request.json(); if (!name) { return NextResponse.json({ error: 'Name is required' }, { status: 400 }); } const special = await prisma.special.create({ data: { name, maxAttempts: Number(maxAttempts), unlockSteps, launchDate: launchDate ? new Date(launchDate) : null, endDate: endDate ? new Date(endDate) : null, }, }); return NextResponse.json(special); } export async function DELETE(request: Request) { const { id } = await request.json(); if (!id) { return NextResponse.json({ error: 'ID required' }, { status: 400 }); } await prisma.special.delete({ where: { id: Number(id) } }); return NextResponse.json({ success: true }); } export async function PUT(request: Request) { const { id, name, maxAttempts, unlockSteps, launchDate, endDate } = await request.json(); if (!id) { return NextResponse.json({ error: 'ID required' }, { status: 400 }); } const updated = await prisma.special.update({ where: { id: Number(id) }, data: { ...(name && { name }), ...(maxAttempts && { maxAttempts: Number(maxAttempts) }), ...(unlockSteps && { unlockSteps }), launchDate: launchDate ? new Date(launchDate) : null, endDate: endDate ? new Date(endDate) : null, }, }); return NextResponse.json(updated); }