<?php

namespace App\Models;

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

class CourseEnrollment extends Model
{
    protected $fillable = [
        'user_id',
        'course_id',
        'progress',
        'enrollment_date',
        'status',
        'last_accessed_at',
        'completed_at',
        'payment_method_id',
    ];

    protected function casts(): array
    {
        return [
            'progress' => 'integer',
            'enrollment_date' => 'date',
            'last_accessed_at' => 'datetime',
            'completed_at' => 'datetime',
        ];
    }

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

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

    /**
     * Get the progress records for this enrollment.
     */
    public function progress(): HasMany
    {
        return $this->hasMany(CourseProgress::class, 'enrollment_id');
    }
}
