<?php

namespace App\Classes\FTN\Process\Echomail;

use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Log;

use App\Classes\FTN\{Message,Process};
use App\Notifications\Echomails\Test as TestNotification;

/**
 * Process messages to Test
 *
 * @package App\Classes\FTN\Process
 */
final class Test extends Process
{
	private const LOGKEY = 'RT-';

	private const testing = ['test','testing'];

	public static function handle(Message $msg): bool
	{
		if ((strtolower($msg->user_to) !== 'all') || ! in_array(strtolower($msg->subject),self::testing))
			return FALSE;

		// @todo Need to limit this to areas defined in config.
		Log::info(sprintf('%s:- Processing TEST message from (%s) [%s]',self::LOGKEY,$msg->user_from,$msg->fftn));

		Notification::route('echomail',$msg->echoarea)->notify(new TestNotification($msg));

		return TRUE;
	}
}