<?php

namespace App\Http\Controllers\Student;

use App\Http\Controllers\Admin\PageController;
use App\Http\Controllers\Student\Concerns\ResolvesStudentScope;
use App\Models\Assessment;
use Illuminate\View\View;

class ExamController extends PageController
{
    use ResolvesStudentScope;

    public function index(): View
    {
        $student = $this->ensureStudent();
        $classIds = $this->studentScope()->classIds($student);

        $exams = Assessment::query()
            ->with(['subject', 'schoolClass', 'term'])
            ->whereIn('class_id', $classIds)
            ->where('status', 'active')
            ->orderBy('assessment_date')
            ->paginate(20);

        return $this->page('student.exams.index', [
            'crumbTitle' => 'Exams',
            'crumbSub' => 'Exam timetable & information',
            'exams' => $exams,
        ]);
    }
}
