<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class EmailSubscriber extends Model
{
    protected $fillable = [
        'email', 'name', 'subscribed_at', 'unsubscribed_at', 'source',
    ];

    protected function casts(): array
    {
        return [
            'subscribed_at' => 'datetime',
            'unsubscribed_at' => 'datetime',
        ];
    }

    public function getIsActiveAttribute(): bool
    {
        return $this->unsubscribed_at === null;
    }
}
