<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class StudentTimetableController extends Controller
{
    public function index()
    {
        // Get logged-in user's registration number
        $regNo = strtoupper(Auth::user()->registration_number);

        // Join timetables with courses using course_code
        $timetable = DB::table('timetables as t')
            ->join('courses as c', 't.course_code', '=', 'c.course_code')
            ->where('t.registration_number', $regNo)
            ->orderBy('t.time')
            ->select(
                't.time',
                't.course_code',
                'c.course_description',
                't.campus',
                't.venue',
                't.duration'
            )
            ->get();

        return view('student.timetable', compact('timetable'));
    }
}
