const Product = require("../models/Product");
const Category = require("../models/Category");
const MarbleSpace = require("../models/MarbleSpace");

exports.dashboardStats = async (req, res) => {
  try {
    const totalProducts = await Product.countDocuments();

    const totalCategories = await Category.countDocuments();

    const totalMarbleSpaces = await MarbleSpace.countDocuments();

    const latestProducts = await Product.find()
      .populate("category")
      .populate("marble_space")
      .sort({ _id: -1 })
      .limit(10);

    res.json({
      totalProducts,
      totalCategories,
      totalMarbleSpaces,
      latestProducts,
    });
  } catch (error) {
    res.status(500).json({
      message: error.message,
    });
  }
};
