<?php

namespace App\Models;

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

class HomeFeature extends Model
{
    use HasFactory;

    protected $fillable = [
        'title',
        'description',
        'icon',
        'icon_type',
        'icon_image',
        'bg_color',
        'icon_color',
        'text_color',
        'sort_order',
        'is_active',
    ];

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

    protected $appends = ['icon_display_url'];

    /**
     * Get the icon display URL (for images) or emoji
     */
    public function getIconDisplayUrlAttribute()
    {
        if ($this->icon_type === 'image' && $this->icon_image) {
            return url('storage/' . $this->icon_image);
        }
        return $this->icon; // Return emoji as-is
    }

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    public function scopeOrdered($query)
    {
        return $query->orderBy('sort_order');
    }
}
