<?php

namespace App\Notifications;

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


class TransactionNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     */
    public $transaction;
    public $channels;
    public $data;
    public function __construct(Transaction $transaction , $data = null, $channel = ['database'])
    {
        //
        $this->transaction = $transaction;
        $this->channels = $channel;
        $this->data = $data ?? '';
    }

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

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
       
        return (new MailMessage)
                    ->subject(ucfirst($this->transaction->type).' Notification')
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        $transaction = [
            'amount' => $this->transaction->amount,
            'coin' => $this->transaction->coin?->symbol,
            'transactionID' =>$this->transaction->txn_id,
            ];
        return [
            'title' => ucfirst($this->transaction->type).' Notification',
            'type' => NotificationType::TRANSACTION,
            'details' => $transaction,
            'data' => $this->data
        ];
    }
    
    
}
