<?php

namespace App\Notifications\Netmails;

use Illuminate\Support\Facades\Log;

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

class PacketPasswordInvalid extends Netmails
{
	use PageTemplate;

	private const LOGKEY = 'NPP';

	private string $packet;
	private string $invalidpass;

	/**
	 * Create a new notification instance.
	 */
	public function __construct(string $invalidpass,string $packet)
	{
		parent::__construct();

		$this->invalidpass = $invalidpass;
		$this->packet = $packet;
	}

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

		Log::info(sprintf('%s:+ Creating netmail to [%s] - system using invalid packet password',self::LOGKEY,$ao->ftn));

		$o->subject = $this->invalidpass.':Incorrect Packet Password';
		$o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_PKTPASSWD|Message::FLAG_CRASH);

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

		if ($this->invalidpass)
			$msg->addText(
				sprintf("Hi there,\r\r".
				"You sent me a mail packet (%s) with the incorrect password \"%s\". It wasnt processed.\r\r"
					,$this->packet,$this->invalidpass));
		else
			$msg->addText(
				sprintf("Hi there,\r\r".
					"You sent me a mail packet (%s) with no password? It wasnt processed.\r\r"
					,$this->packet));

		$msg->addText("Head over to the website if you dont know what your packet password should be :)\r");

		$o->msg = $msg->render();
		$o->tagline = 'Safety first, password second.';

		$o->save();

		return $o;
	}

	/**
	 * Get the array representation of the notification.
	 *
	 * @return array<string, mixed>
	 */
	public function toArray(object $notifiable): array
	{
		return [
			//
		];
	}
}