<?php

namespace Mamad\Wallet\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Mamad\Transaction\Models\Transaction;
use Mamad\Transaction\Repository\TransactionRepository;
use Mamad\Wallet\Models\Wallet;
use Mamad\Wallet\Repository\WalletRepository;

class transaction_increase_wallet_listener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {

        $wallet=$event->transaction->transactionAble;
        if($wallet instanceof Wallet){
            TransactionRepository::updateStatus($event->transaction,Transaction::$COMPLETED);
            TransactionRepository::update_transactionAble_Status($event->transaction->transactionable,Transaction::$COMPLETED);
           WalletRepository::increase($event->transaction->price);

        }
    }
}
