<?php

namespace App\Notifications;

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

class TransferNotif extends Notification
{
    use Queueable;
    public $transfer;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($transfer)
    {
        $this->transfer = $transfer;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database','broadcast'];
    }


    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        $user = auth()->user();
        return [
            'amount' => $this->transfer->transaction->amount,
            'sender'=>[
                'name' => $user->name,
                'image'=> $user->image??'user2-160x160.jpg'
            ],
            'message'=>trans('messages.transfer_notif',['amount'=>formatPrice($this->transfer->transaction->amount*$this->transfer->transaction->exchange_rate,$this->transfer->transaction->currency_code)]),
            'time' => $this->transfer->created_at->format('h:i')
        ];
    }
}
