<?php

declare(strict_types=1);

namespace App\Notifications\Payments;

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

final class PaymentDisputed extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public Transaction $transaction,
        public string $recipient
    ) {}

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['database'];
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        $disputer = $this->transaction->disputedBy;
        $message = $this->recipient === 'owner'
            ? $disputer->name.' disputed the payment for booking #'.$this->transaction->booking_id
            : 'The property owner disputed your payment for '.$this->transaction->property->title;

        return [
            'title' => 'Payment Disputed',
            'message' => $message.' - Admin will review and resolve.',
            'icon' => 'exclamation-triangle',
            'url' => route('guest.dashboard'),
            'transaction_id' => $this->transaction->id,
            'booking_id' => $this->transaction->booking_id,
        ];
    }
}
