<?php

namespace App\Models;

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

/**
 * One row per agent push: snapshot of the mail queue (Exim or Postfix).
 *
 * Frozen messages are the alarming ones — Exim freezes a mail when it can't
 * be delivered after retries (typically a misconfigured remote MX or domain
 * that no longer exists). A growing frozen count usually means a customer
 * has a runaway script.
 */
class EmailQueueSnapshot extends Model
{
    use HasFactory;
    public $timestamps = false;

    protected $fillable = [
        'server_id', 'measured_at',
        'queue_total', 'queue_frozen', 'queue_deferred', 'queue_active',
        'top_sender_domain', 'top_sender_count',
        'bounces_last_hour', 'rejects_last_hour',
    ];

    protected $casts = [
        'measured_at' => 'datetime',
    ];

    public function server(): BelongsTo
    {
        return $this->belongsTo(Server::class);
    }
}
