import { Router } from "express";
// import { genSalt, hash, compare } from "bcryptjs";
// import jwt from "jsonwebtoken";
import passport from "passport";
import User from "../models/user.js";
import "dotenv/config";

const router = Router();

router.get(
  "/doctors",
  passport.authenticate("jwt", { session: false }),
  async (req, res) => {
    try {
      const doctors = await User.find({ role: "doctor" });
      // const messages = await User.find({role}).sort({ timestamp: -1 });

      res.json(doctors);
    } catch (err) {
      res.status(500).json({ error: "Error retrieving messages" });
    }
  },
);

router.get(
  "/patients",
  passport.authenticate("jwt", { session: false }),
  async (req, res) => {
    try {
      const patients = await User.find({ role: "patient" });
      // const messages = await User.find({role}).sort({ timestamp: -1 });

      res.json(patients);
    } catch (err) {
      res.status(500).json({ error: "Error retrieving messages" });
    }
  },
);

export default router;
