<?php

namespace App\Models;

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

class IllustrationCategory extends Model
{
    protected $table = 'illustration_category';

    protected $fillable = [
        'slug', 'name_en', 'description', 'image',
        'is_show_in_home', 'is_delete', 'status'
    ];

    protected $casts = [
        'is_delete' => 'integer',
        'status' => 'integer',
        'is_show_in_home' => 'integer',
    ];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($category) {
            if (empty($category->slug)) {
                $category->slug = Str::slug($category->name_en);
            }
        });

        static::updating(function ($category) {
            if ($category->isDirty('name_en')) {
                $category->slug = Str::slug($category->name_en);
            }
        });
    }
}
