<?php

namespace App\Models\Email;

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

class EmailRecipient extends Model {

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

    /**
     * Get the recipient model
     */
    public function recipient(): MorphTo {
        return $this->morphTo();
    }

    /**
     * Get the events (open, click, bounce) associated with this specific recipient.
     * This is the relationship that tracks recipient-specific activity.
     */
    public function events(): HasMany {
        return $this->hasMany(EmailEvent::class, 'email_recipient_id');
    }
}

