<?php

namespace App\Models;

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

class Hero extends Model
{
    use HasFactory;

    protected $fillable = [
        'title_line_1',
        'title_line_2',
        'title_line_3',
        'description',
        'button_text',
        'button_link',
        'video_url',
        'side_images',
        'is_active',
        'sort_order',
    ];

    protected function casts(): array
    {
        return [
            'side_images' => 'array',
            'is_active'   => 'boolean',
            'sort_order'  => 'integer',
        ];
    }

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

    public function sideImageUrls(): array
    {
        return collect($this->side_images ?? [])
            ->map(fn ($i) => asset('storage/' . $i))
            ->toArray();
    }
}
