<?php

namespace App\Notifications;

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

class TrackingInfoNotification extends Notification implements ShouldQueue
{
    use Queueable;

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

    /**
     * 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
    {
        $url = route('transactions.show', $this->transaction);

        return (new MailMessage)
            ->subject("Your Item Has Shipped - Tracking Number Provided")
            ->greeting("Great news!")
            ->line("Your purchase is on its way!")
            ->line('')
            ->line("Item: {$this->transaction->item->title}")
            ->line("Tracking Number: {$this->transaction->tracking_number}")
            ->line('')
            ->line("You can track your package using the tracking number above. Once you receive the item, please confirm receipt on the transaction page.")
            ->action('View Transaction & Tracking', $url)
            ->line('Thank you for shopping on Xeek!');
    }
}
