<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SpaCourse extends Model
{
    use SoftDeletes;

    protected $table = 'spa_courses';

    protected $fillable = [
        'name',
        'slug',
        'category',
        'main_image_path',
        'gallery_image_paths',
        'duration_minutes',
        'price',
        'short_description',
        'description',
        'highlights',
        'contraindications',
        'sort_order',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'gallery_image_paths' => 'array',
            'highlights' => 'array',
            'contraindications' => 'array',
            'is_active' => 'bool',
            'sort_order' => 'int',
            'duration_minutes' => 'int',
            'price' => 'decimal:2',
        ];
    }

    protected static function booted(): void
    {
        static::updating(function (SpaCourse $model): void {
            if ($model->isDirty('slug')) {
                $model->slug = $model->getOriginal('slug');
            }
        });
    }
}
