import { NextRequest, NextResponse } from "next/server"
import { prisma } from "@//app/lib/prisma"

// 创建分类
export async function POST(request: NextRequest) {
  try {
    const data = await request.json()
    const category = await prisma.category.create({
      data: {
        name: data.name,
        icon: data.icon || null,
        description: data.description || null,
      },
    })
    return NextResponse.json(category)
  } catch (error) {
    return NextResponse.json({ error: "创建失败" }, { status: 500 })
  }
}

// 获取所有分类
export async function GET() {
  try {
    const categories = await prisma.category.findMany({
      include: { _count: { select: { agents: true } } },
    })
    return NextResponse.json(categories)
  } catch (error) {
    return NextResponse.json({ error: "获取失败" }, { status: 500 })
  }
}
