<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Course;

class CourseDetailsController extends Controller
{

   public function showCourseDetails(Request $request, $courseId)
{
    $course = Course::findOrFail($courseId);
    $userEnrolled = false;

    if (auth()->check()) {
        $userId = auth()->id();

       
        $procedureName = 'IsUserEnrolledInCourse';

        \DB::statement("CALL {$procedureName}(?, ?, @isEnrolled)", [$userId, $courseId]);

        $isEnrolledResult = \DB::select("SELECT @isEnrolled as isEnrolled");
        if ($isEnrolledResult) {
            $userEnrolled = (bool) ($isEnrolledResult[0]->isEnrolled);
        }
    }

    return view('CourseDetails', compact('course', 'userEnrolled'));
}


}