<?php

namespace App\Models;

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

class PricingPlan extends Model
{
    use HasFactory;

    protected $fillable = [
        'name', 'description', 'features', 'price', 'period',
        'payment_processor', 'campaigns_limit', 'messages_limit',
        'contacts_limit', 'plugins', 'is_active',
    ];

    protected function casts(): array
    {
        return [
            'price'     => 'decimal:2',
            'is_active' => 'boolean',
        ];
    }

    public function getFeaturesArrayAttribute(): array
    {
        return $this->features
            ? array_filter(array_map('trim', explode(',', $this->features)))
            : [];
    }
}
