import { NextResponse } from "next/server";
import { isPluginEnabled, PLUGINS, type PluginKey } from "./plugins";

// Call at the top of any API route that belongs to a plugin. Returns a
// ready-to-return 404 response if the plugin is off, or null if the route
// should proceed normally:
//
//   const gate = pluginGate("wallet");
//   if (gate) return gate;
export function pluginGate(key: PluginKey) {
  if (isPluginEnabled(key)) return null;
  return NextResponse.json({ error: `${PLUGINS[key]?.name ?? key} is disabled` }, { status: 404 });
}
