<?php

namespace App\Notifications;

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

class OfferRejected extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(private Offer $offer)
    {
    }

    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        $url = route('items.show', $this->offer->item);

        return (new MailMessage)
            ->subject("Your Offer Was Declined - {$this->offer->item->title}")
            ->greeting("Offer Update")
            ->line("Your offer on {$this->offer->item->title} has been declined by the seller.")
            ->line("Offered Price: \$" . number_format($this->offer->offered_price, 2))
            ->when($this->offer->seller_message, function ($mail) {
                return $mail->line("Seller's Message: \"{$this->offer->seller_message}\"");
            })
            ->line('')
            ->action('View Item', $url)
            ->line('Feel free to make another offer or browse other items!');
    }
}
