<?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 PurchaseConfirmed extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        private Transaction $transaction
    ) {
    }

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

    public function toMail(object $notifiable): MailMessage
    {
        $item = $this->transaction->item;

        return (new MailMessage)
            ->subject("It's Yours: {$item->title}")
            ->greeting('Congratulations!')
            ->line("The seller has confirmed the sale of \"{$item->title}\" to you for \$" . number_format($this->transaction->price, 2) . '.')
            ->line('A transaction record has been created. The seller will add tracking information once the item ships.')
            ->action('View Transaction', route('transactions.show', $this->transaction))
            ->line('Once the item arrives, please confirm receipt on the transaction page.');
    }
}
