<?php

declare(strict_types=1);

namespace App\Notifications;

use App\Models\Service;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ServiceTerminatedNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public Service $service,
    ) {}

    /** @return array<int, string> */
    public function via(object $notifiable): array
    {
        return ['mail', 'database'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        $billingUrl = 'https://'.config('app.domains.account').'/billing';

        $mail = (new MailMessage)
            ->subject('Service Terminated')
            ->greeting("Hello {$notifiable->name},")
            ->line('Your service has been permanently terminated due to prolonged non-payment.');

        if ($this->service->hostname) {
            $mail->line("Hostname: **{$this->service->hostname}**");
        }

        if ($this->service->ipv4_address) {
            $mail->line("IP Address: **{$this->service->ipv4_address}**");
        }

        $mail->line("Service Type: **{$this->service->service_type}**");

        return $mail
            ->action('View Account', $billingUrl)
            ->line('All data associated with this service has been permanently removed.')
            ->line('If you wish to start a new service, please visit our plans page.');
    }

    /** @return array<string, mixed> */
    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'service_terminated',
            'service_id' => $this->service->id,
            'service_type' => $this->service->service_type,
            'hostname' => $this->service->hostname,
            'ip_address' => $this->service->ipv4_address,
            'message' => "Your {$this->service->service_type} service has been permanently terminated.",
        ];
    }
}
