import { NextResponse } from "next/server"
import { getDatabases, getDatabaseStructure } from "@/lib/mongodb-mock-connector" // 更新导入路径

export async function GET(request: Request) {
  try {
    const { searchParams } = new URL(request.url)
    const database = searchParams.get("database")

    if (database) {
      // 获取指定数据库的结构
      const structure = await getDatabaseStructure(database)
      return NextResponse.json({ success: true, data: structure })
    } else {
      // 获取所有数据库列表
      const databases = await getDatabases()
      return NextResponse.json({ success: true, data: databases })
    }
  } catch (error) {
    console.error("数据库结构查询失败:", error)
    return NextResponse.json(
      { success: false, message: "数据库结构查询失败", error: (error as Error).message },
      { status: 500 },
    )
  }
}
