<?php

namespace App\Notifications;

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

class ItemSold extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     */
    public function __construct(
        private Item $item
    ) {
    }

    /**
     * Get the notification's delivery channels.
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        $itemUrl = route('items.show', $this->item);

        return (new MailMessage)
            ->subject("Item Sold - No Longer Available")
            ->greeting("Update on Watched Item")
            ->line("An item you were watching has been sold and is no longer available.")
            ->line('')
            ->line("Item: {$this->item->title}")
            ->line("Seller: {$this->item->user->name}")
            ->line('')
            ->action('View Similar Items', route('items.index'))
            ->line('Continue browsing for similar items on Xeek.');
    }
}
