<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Exercise extends Model
{
    use HasFactory;

    protected $fillable = [
        'title', 'slug', 'description', 'content', 'category', 'duration', 'image', 'is_premium',
    ];

    protected $casts = [
        'is_premium' => 'boolean',
    ];

    protected static function boot()
    {
        parent::boot();
        static::creating(function ($exercise) {
            if (empty($exercise->slug)) {
                $exercise->slug = \Str::slug($exercise->title);
            }
        });
    }
}
