<?php

namespace App\Notifications;

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

class DomainStatusNotification extends Notification
{
    use Queueable;

    public function __construct(
        public LicenseDomain $domain,
        public string $oldStatus,
        public string $newStatus
    ) {}
    
    public function via($notifiable): array
    {
        return ['database'];
    }
    public function toDatabase($notifiable): array
    {
        $message = sprintf(
            'Domain %s is %s',
            $this->domain->domain,
            strtoupper($this->newStatus)
        );
        return [
            'license_id'   => $this->domain->license_id ?? null,
            'license_key'  => $this->domain->license_key ?? null,
            'domain_id'    => $this->domain->id,
            'domain'       => $this->domain->domain,
            'old_status'   => $this->oldStatus,
            'new_status'   => $this->newStatus,
            'status_label' => $this->newStatus === 'up' ? 'UP' : 'DOWN',
            'message'      => $message,
        ];
    }
}
