<?php

namespace App\Models;

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

/**
 * @property int $id
 * @property string $name
 * @property string $image
 * @property bool $active
 * @property \Illuminate\Support\Facades\Date $created_at
 * @property \Illuminate\Support\Facades\Date $updated_at
 */
class Brand extends Model
{
    /**
     * Casts
     *
     * @var array<string, string>
     */
    protected $casts = [
        'active' => 'boolean',
    ];

    /**
     * Booted
     */
    protected static function booted(): void
    {
        static::deleted(function ($model) {
            if ($model->image) {
                Storage::disk('public')->delete($model->image);
            }
        });
    }

    /**
     * Image url
     */
    public function imageUrl(): string
    {
        return url('/storage/'.$this->image);
    }
}
