<?php

namespace App\Notifications;

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

class DnsZoneAlertNotification extends Notification implements ShouldQueue
{
    use Queueable;

    protected $dnsZone;
    protected $alertType;
    protected $daysLeft;

    /**
     * Create a new notification instance.
     */
    public function __construct(DnsZone $dnsZone, string $alertType, int $daysLeft)
    {
        $this->dnsZone = $dnsZone;
        $this->alertType = $alertType;
        $this->daysLeft = $daysLeft;
    }

    /**
     * Get the notification's delivery channels.
     */
    public function via(object $notifiable): array
    {
        return ['database'];
    }

    /**
     * Get the array representation of the notification.
     */
    public function toArray(object $notifiable): array
    {
        $messages = [
            'first_warning' => "Zona DNS {$this->dnsZone->domain} are probleme cu nameserver-ele. {$this->daysLeft} zile până la suspendare.",
            'second_warning' => "ATENȚIE! Zona DNS {$this->dnsZone->domain} va fi suspendată în {$this->daysLeft} zi.",
            'final_warning' => "URGENT! Zona DNS {$this->dnsZone->domain} va fi suspendată MÂINE dacă nu rezolvi problema cu nameserver-ele.",
        ];

        return [
            'message' => $messages[$this->alertType] ?? 'Alertă DNS Zone',
            'zone_id' => $this->dnsZone->id,
            'domain' => $this->dnsZone->domain,
            'alert_type' => $this->alertType,
            'days_left' => $this->daysLeft,
            'icon' => 'fa-exclamation-triangle',
            'color' => $this->alertType === 'final_warning' ? 'red' : ($this->alertType === 'second_warning' ? 'orange' : 'yellow'),
            'action_url' => route('dns-zones.show', $this->dnsZone->domain),
        ];
    }
}
