<?php

namespace App\Notifications;

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

class BuyerLeftQueue extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        private Item $item,
        private User $buyer,
        private bool $wasPrimary
    ) {
    }

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

    public function toMail(object $notifiable): MailMessage
    {
        $mail = (new MailMessage)
            ->subject("Buyer Withdrew: {$this->item->title}")
            ->line("{$this->buyer->name} has withdrawn from the buy queue for \"{$this->item->title}\".");

        if ($this->wasPrimary) {
            $mail->line('They were the primary buyer. If there are backup buyers, the next one has been promoted and notified.');
        }

        return $mail
            ->action('Manage Buyers', route('items.manage-queue', $this->item))
            ->line('Log in to your Xeek account to manage interested buyers.');
    }
}
