<?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 OfferCountered 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("Counter Offer on Your Offer - {$this->offer->item->title}")
            ->greeting("The seller sent a counter offer!")
            ->line("A seller has countered your offer on {$this->offer->item->title}")
            ->line("Your Offer: \$" . number_format($this->offer->offered_price, 2))
            ->line("Counter Offer: \$" . number_format($this->offer->counter_price, 2))
            ->when($this->offer->seller_message, function ($mail) {
                return $mail->line("Seller's Message: \"{$this->offer->seller_message}\"");
            })
            ->line('')
            ->action('View Counter Offer', $url)
            ->line('You can accept, make another counter offer, or withdraw.');
    }
}
