import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";

export async function GET() {
  try {
    const benefits = await prisma.premiumBenefit.findMany({
      where: { active: true },
      orderBy: { createdAt: "asc" },
    });

    const grouped = {
      premium: benefits.filter((b) => b.tier === "premium"),
      pro: benefits.filter((b) => b.tier === "pro"),
    };

    return NextResponse.json({ benefits: grouped });
  } catch (error) {
    console.error("GET /api/premium/benefits error:", error);
    return NextResponse.json(
      { error: "Internal server error" },
      { status: 500 }
    );
  }
}
