<?php

namespace App\Models\Email;

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

class EmailEvent extends Model {
    protected $table = 'email_events';

    protected $casts = [
        'data' => 'array',
        'occurred_at' => 'datetime',
    ];

    /**
     * Get the email that the event belongs to.
     */
    public function email(): BelongsTo {
        return $this->belongsTo(Email::class);
    }

    /**
     * Get the specific recipient this event is associated with.
     * This ensures the event is linked to the historical recipient record.
     */
    public function recipient(): BelongsTo {
        return $this->belongsTo(EmailRecipient::class, 'email_recipient_id');
    }
}
