<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Servicio extends Model
{
    protected $fillable = [
        'nombre', 'descripcion', 'caracteristicas', 'icono', 'imagen',
        'precio_desde', 'tipo', 'badge', 'badge_color', 'url_demo',
        'orden', 'destacado', 'activo'
    ];

    protected $casts = [
        'activo' => 'boolean',
        'destacado' => 'boolean',
    ];

    public function scopeActivos($query)
    {
        return $query->where('activo', true)->orderBy('orden');
    }

    public function getCaracteristicasArrayAttribute()
    {
        if (!$this->caracteristicas) return [];
        return array_filter(array_map('trim', explode("\n", $this->caracteristicas)));
    }
}
