<?php
namespace App\Services;

class ReportService {
    public function __construct(private \PDO $pdo) {}

    public function studentProgressRows(): array {
        return $this->pdo->query("SELECT s.student_number, u.first_name, u.last_name, u.email, s.enrollment_status, s.payment_status, COUNT(e.id) AS enrollments FROM students s JOIN users u ON s.user_id = u.id LEFT JOIN enrollments e ON e.student_id = s.id GROUP BY s.id ORDER BY s.created_at DESC")->fetchAll();
    }

    public function paymentRows(): array {
        return $this->pdo->query("SELECT p.*, s.student_number, u.first_name, u.last_name, pk.name AS package_name FROM payments p JOIN students s ON p.student_id = s.id JOIN users u ON s.user_id = u.id LEFT JOIN packages pk ON p.package_id = pk.id ORDER BY p.created_at DESC")->fetchAll();
    }

    public function exportCsv(array $rows, array $headers, string $filename): void {
        export_csv($rows, $headers, $filename);
    }
}
