import { Router } from "express";
import User from "../models/user.js";
import Verification from "../models/verification.js";
import passport from "passport";

const router = Router();

router.get(
  "/summary",
  passport.authenticate("jwt", { session: false }),
  async (req, res) => {
    try {
      const totalDoctors = await User.countDocuments({ role: "doctor" });
      const totalPatients = await User.countDocuments({ role: "patient" });
      const pendingVerifications = await Verification.countDocuments({
        verifiedStatus: "not_verified",
      });
      const completedVerifications = await Verification.countDocuments({
        verifiedStatus: "verified",
      });

      res.json({
        totalDoctors,
        totalPatients,
        pendingVerifications,
        completedVerifications,
      });
    } catch (err) {
      console.error(err);
      res.status(500).json({ error: "Failed to fetch admin summary" });
    }
  },
);

export default router;
