<?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 OfferAccepted 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 Accepted! - {$this->offer->item->title}")
            ->greeting("Great news!")
            ->line("Your offer has been accepted by {$this->offer->seller->name}!")
            ->line("Item: {$this->offer->item->title}")
            ->line("Accepted Price: \$" . number_format($this->offer->offered_price, 2))
            ->line('')
            ->line("You can now contact the seller to arrange payment and delivery.")
            ->action('View Item & Contact Seller', $url);
    }
}
