import type { Request, Response, NextFunction } from "express";

export function requireAdmin(req: Request, res: Response, next: NextFunction) {
  const key = req.headers["x-admin-key"];
  const expected = process.env.ADMIN_API_KEY;
  if (!expected || key !== expected) {
    res.status(403).json({ success: false, error: { code: "FORBIDDEN", message: "管理员权限不足" } });
    return;
  }
  next();
}
