const Student = require('../models/Student');
const Book = require('../models/Book');
const Borrow = require('../models/Borrow');

exports.getstats = async (req, res) => {
  try {
    const totalStudents = await Student.countDocuments();
    const totalBooks = await Book.countDocuments();
    const currentlyBorrowed = await Borrow.countDocuments({ status: 'borrowed' });
    const totalReturned = await Borrow.countDocuments({ status: 'returned' });

    res.status(200).json({
      totalStudents,
      totalBooks,
      currentlyBorrowed,
      totalReturned,
    });
  } catch (error) {
    res.status(500).json({ msg: 'Failed to load stats', error: error.message });
  }
};
