<?php

declare(strict_types=1);

namespace App\Notifications;

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

class QuoteSentNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public Quote $quote,
        public string $signedUrl,
    ) {}

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

    public function toMail(object $notifiable): MailMessage
    {
        $total = number_format((float) $this->quote->total, 2);
        $currency = strtoupper($this->quote->currency);
        $recipientName = $this->quote->getRecipientName() ?? 'there';
        $validUntil = $this->quote->valid_until?->format('M d, Y');

        $message = (new MailMessage)
            ->subject("Quote {$this->quote->number} from EZSCALE")
            ->greeting("Hello {$recipientName}!")
            ->line("We've prepared a quote for you.")
            ->line("**Quote #:** {$this->quote->number}")
            ->line("**Total:** {$currency} {$total}");

        if ($validUntil) {
            $message->line("**Valid Until:** {$validUntil}");
        }

        if ($this->quote->notes) {
            $message->line("**Notes:** {$this->quote->notes}");
        }

        $message->action('View Quote', $this->signedUrl)
            ->line('You can accept or decline this quote using the link above.')
            ->line('Thank you for considering EZSCALE!');

        return $message;
    }
}
