<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Storage;

class CollectionItem extends Model
{
    protected $fillable = ['collection_id', 'title', 'subtitle', 'image', 'order', 'is_active'];

    public function collection(): BelongsTo
    {
        return $this->belongsTo(Collection::class);
    }

    protected static function booted(): void
    {
        static::deleting(function (CollectionItem $item) {
            if ($item->image) {
                Storage::disk('public')->delete($item->image);
            }
        });
    }
}
