import { NextRequest, NextResponse } from 'next/server';
import { PrismaClient } from '@prisma/client';
import { requireStaffAuth } from '@/lib/auth';

const prisma = new PrismaClient();

export async function GET(request: NextRequest) {
    const { error, context } = await requireStaffAuth(request);
    if (error || !context) return error!;

    if (context.role !== 'curator') {
        return NextResponse.json(
            { error: 'Only curators can access this endpoint' },
            { status: 403 }
        );
    }

    const [genres, specials] = await Promise.all([
        prisma.curatorGenre.findMany({
            where: { curatorId: context.curator.id },
            select: { genreId: true },
        }),
        prisma.curatorSpecial.findMany({
            where: { curatorId: context.curator.id },
            select: { specialId: true },
        }),
    ]);

    return NextResponse.json({
        id: context.curator.id,
        username: context.curator.username,
        isGlobalCurator: context.curator.isGlobalCurator,
        genreIds: genres.map(g => g.genreId),
        specialIds: specials.map(s => s.specialId),
    });
}


