<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Events\MessageSent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class LogSentMessage
{
	private const LOGKEY = 'LSM';

	/**
	 * Handle the event.
	 *
	 * @param MessageSent $event
	 * @return void
	 */
    public function handle(MessageSent $event)
    {
        Log::debug(
			sprintf('%s:Email to [%s] with subject [%s] sent [%s]',
				self::LOGKEY,
				collect($event->data['message']->getTo())->transform(function($item) { return $item->getAddress(); })->join(','),
				$event->data['message']->getSubject(),
				$event->sent->getMessageId(),
			),
			['debug'=>$event->sent->getDebug()]);
    }
}