<?php

namespace App\Classes\FTN\Process\Netmail;

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

use App\Classes\FTN\Process;
use App\Models\{Echomail,Netmail};
use App\Notifications\Netmails\Areafix as AreafixNotification;
use App\Notifications\Netmails\Areafix\NotConfiguredHere as AreafixNotConfiguredHereNotification;

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

	public static function handle(Echomail|Netmail $mo): bool
	{
		if (strtolower($mo->to) !== 'areafix')
			return FALSE;

		Log::info(sprintf('%s:- Processing AREAFIX message from (%s) [%s]',self::LOGKEY,$mo->from,$mo->fftn));

		// If this is not a node we manage, then respond with a sorry can help you
		if ($mo->fftn->system->sessions->count())
			Notification::route('netmail',$mo->fftn)->notify(new AreafixNotification($mo));
		else
			Notification::route('netmail',$mo->fftn)->notify(new AreafixNotConfiguredHereNotification($mo));

		return TRUE;
	}
}