<?php

namespace domain\Payment\Event;

use domain\Order\Order\Event\OrderDeleteEvent;
use domain\Order\Order\Order;
use domain\Payment\PaymentModule;
use justcoded\yii2\eventlistener\observers\Observer;
use domain\User\User\UserModule;

class OrderObserver extends Observer
{
    public function events()
    {
        return [
            Order::EVENT_DELETE => 'onOrderDelete'
        ];
    }

    public function onOrderDelete(OrderDeleteEvent $event)
    {
        $order = $event->order;
        $paymentManager = PaymentModule::getInstance();
        $userModule = UserModule::getInstance();

        $paymentManager->refundOrderCredit($order, $userModule->getCurrent());
    }
}