<?php

namespace App\Models;

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

class Divider extends Model
{
    protected $fillable = [
        'title',
        'text_alignment',
        'font_size',
        'icon_type',
        'icon',
        'icon_image',
        'divider_style',
        'divider_color',
        'divider_height',
        'spacing_top',
        'spacing_bottom',
        'is_active',
        'sort_order',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'divider_height' => 'integer',
        'font_size' => 'integer',
        'spacing_top' => 'integer',
        'spacing_bottom' => 'integer',
        'sort_order' => 'integer',
    ];

    // Accessor for icon display URL
    public function getIconDisplayUrlAttribute()
    {
        if ($this->icon_type === 'image' && $this->icon_image) {
            return Storage::disk('public')->url($this->icon_image);
        }
        return null;
    }

    // Accessor for icon_image URL
    public function getIconImageUrlAttribute()
    {
        if ($this->icon_image) {
            return Storage::disk('public')->url($this->icon_image);
        }
        return null;
    }
}
