<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Newsletter extends Model
{
    protected $fillable = ['subject', 'content', 'scheduled_at', 'sent_at', 'recipients_count'];

    protected $casts = [
        'scheduled_at' => 'datetime',
        'sent_at' => 'datetime',
    ];

    public function isSent(): bool
    {
        return $this->sent_at !== null;
    }

    public function isScheduled(): bool
    {
        return $this->scheduled_at !== null && ! $this->isSent();
    }

    public function isDueToSend(): bool
    {
        return $this->isScheduled() && $this->scheduled_at->isPast();
    }
}
