import { verifyToken } from "../auth/auth.js"
import { connection } from "../configs/db.js"
import express from "express"

const reportRoute = express.Router()

// Generate simple report for dashboard

reportRoute.get("/", verifyToken, async (req, res) => {
    try {
        const [students] = await connection.query("SELECT * FROM students")
        const [courses] = await connection.query("SELECT * FROM courses")

        const totalCourse = courses.length
        const totalStudents = students.length

        const averageStudentsPerCourse = (totalStudents / totalCourse) || 0
        const averageCoursesPerStudent = (totalCourse / totalStudents) || 0

        return res.status(200).json({ totalCourse, totalStudents, averageStudentsPerCourse, averageCoursesPerStudent })
    } catch (error) {
        console.log(error)
        return res.status(500).json({ message: "Internal server error" })
    }
})

export default reportRoute