<?php

namespace App\Models;

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

class Course extends Model
{
    protected $fillable = [
        'course_type_id', 'title', 'slug', 'summary', 
        'description', 'price_clp', 'price_usd', 'status', 'image_path'
    ];

    /**
     * Relación: Un curso pertenece a un Tipo de Curso (Categoría)
     */
    public function type()
    {
        // Asegúrate de que apunte a tu modelo de categorías (ej: CourseType)
        return $this->belongsTo(CourseType::class, 'course_type_id'); 
    }

    protected static function boot()
    {
        parent::boot();
        static::creating(function ($course) {
            $course->slug = Str::slug($course->title);
        });
    }

    public function contents()
    {
        return $this->hasMany(CourseContent::class)->orderBy('order', 'asc');
    }

    
}