import User from "../models/user.model.js"
import Student from "../models/student.model.js"
import Payment from "../models/payment.model.js"
import express from "express"
import { verifyToken } from "../auth/auth.js"
const reportRouter = express.Router()

reportRouter.get("/", verifyToken, async(req, res) => {
    try{
        const totalStudents = await Student.find().countDocuments()
        const paymentsRecords = await Payment.find().countDocuments()
        const payments = await Payment.find()
        const totalPayedAmount = payments.reduce((acc, payment) => acc + payment.amount, 0)
        const averageOfStudentWhoPayed = (await Payment.find().countDocuments()) / totalStudents
        return res.status(200).json({ totalStudents, paymentsRecords, totalPayedAmount, averageOfStudentWhoPayed })
    }catch(error){
        console.log(error)
        return res.status(500).json({ message: "Internal server error" })
    }
})
export default reportRouter