<?php

namespace App\Models;

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

class Email extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    /**An Email was created by a Specific User**/
    public function user()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    /**An Email is sent by a specific User**/
    public function sentBy()
    {
        return $this->belongsTo(User::class, 'sent_by');
    }

    /**An Email has many Internal Recipients**/
    public function emailRecipients()
    {
        return $this->hasMany(EmailRecipient::class, 'email_id');
    }

    /**An Email has many attachments on it**/
    public function attachments()
    {
        return $this->hasMany(EmailAttachment::class, 'email_id');
    }
}
