<?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 ServiceTerminationWarningNotification 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('Urgent: Service Termination Warning')
            ->greeting("Hello {$notifiable->name},")
            ->line('Your suspended service is scheduled for **permanent termination in 7 days**.')
            ->line('Once terminated, all data associated with this service will be permanently deleted and cannot be recovered.');

        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('Pay Now to Reactivate', $billingUrl)
            ->line('Please pay the outstanding balance immediately to prevent permanent data loss.');
    }

    /** @return array<string, mixed> */
    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'service_termination_warning',
            '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 will be terminated in 7 days. Pay now to prevent data loss.",
        ];
    }
}
