<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CourseProgress extends Model
{
    protected $fillable = [
        'enrollment_id',
        'course_id',
        'user_id',
        'lesson_id',
        'progress_percentage',
        'lessons_completed',
        'time_spent_minutes',
        'last_accessed_at',
        'completed_at',
        'certificate_eligible',
    ];

    protected function casts(): array
    {
        return [
            'progress_percentage' => 'integer',
            'lessons_completed' => 'integer',
            'time_spent_minutes' => 'integer',
            'certificate_eligible' => 'boolean',
            'last_accessed_at' => 'datetime',
            'completed_at' => 'datetime',
        ];
    }

    /**
     * Get the enrollment that owns the progress.
     */
    public function enrollment(): BelongsTo
    {
        return $this->belongsTo(CourseEnrollment::class, 'enrollment_id');
    }

    /**
     * Get the course.
     */
    public function course(): BelongsTo
    {
        return $this->belongsTo(Course::class);
    }

    /**
     * Get the user.
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Get the lesson.
     */
    public function lesson(): BelongsTo
    {
        return $this->belongsTo(CourseLesson::class);
    }
}
