<?php

namespace App\Notifications\Netmails;

use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Log;

use App\Classes\FTN\Message;
use App\Notifications\Netmails;
use App\Models\{Address,Netmail};
use App\Traits\PageTemplate;

class NodeStatusCleared extends Netmails //implements ShouldQueue
{
	use Queueable,PageTemplate;

	private const LOGKEY = 'NNM';

	/**
	 * Create a new notification instance.
	 */
	public function __construct(private Address $ao)
	{
		parent::__construct();
	}

	/**
	 * Get the mail representation of the notification.
	 */
	public function toNetmail(object $notifiable): Netmail
	{
		$ao = $notifiable->routeNotificationFor(static::via);

		Log::info(sprintf('%s:+ Sending a NODE DOWN|HOLD STATUS CLEARED NETMAIL for address [%s]',self::LOGKEY,$ao->ftn));

		$o = $this->setupNetmail($notifiable);
		$o->subject = 'Your HOLD or DOWN status has been cleared';
		$o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH);

		// Message
		$msg = $this->page(TRUE,'reset');

		$msg->addText(sprintf("Hi %s,\r\r",$this->ao->system->sysop))
			->addText(sprintf("Good news! Your system's HOLD or DOWN status has been **cleared** for address %s, as you recently polled the hub.\r",$this->ao->ftn4d))
			->addText("\r")
			->addText("If you think you've received this netmail by mistake or need help, please let me know.\r");

		$o->msg = $msg->render();
		$o->set_tagline = 'All good to go now';

		$o->save();

		return $o;
	}
}