<?php

namespace App\Models;

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

class CourseType extends Model
{
    protected $fillable = ['name', 'slug', 'description'];

    // Un Tipo de Curso tiene MUCHOS Cursos
    public function courses(): HasMany
    {
        return $this->hasMany(Course::class);
    }

    // Mutator automático para el slug al guardar el nombre
    protected static function boot()
    {
        parent::boot();
        static::creating(function ($type) {
            $type->slug = Str::slug($type->name);
        });
    }
}