<?php

namespace App\Notifications;


use App\Events\Accounts\UserInvited;
use Illuminate\Notifications\Messages\MailMessage;

class InvitationEmail extends AbstractEmail
{

    /** @var UserInvited */
    private $invitation;

    /**
     * InvitationEmail constructor.
     * @param UserInvited $invitation
     */
    public function __construct(UserInvited $invitation) {
        $this->invitation = $invitation;
    }

    public function toMail()
    {
        return (new MailMessage)
            ->subject('Registration Invite')
            ->line($this->senderName().' has sent you an invitation to create an account with us.')
            ->action('Create Account', $this->invitationUrl());
    }

    private function invitationUrl(){
        return url(route('auth.registration', ['email' => $this->invitation->getData()->email, 'hash' => $this->invitation->getData()->hash]));
    }

    private function senderName(){
        $sender = $this->invitation->getData()->sender;
        return $sender->first_name.' '.$sender->last_name;
    }

}