<?php

namespace domain\Document\DeliveryNote\Event;

use domain\Document\DeliveryNote\DeliveryNote;
use domain\Document\Document\DocumentModule;
use justcoded\yii2\eventlistener\observers\Observer;
use domain\Producer\Producer\ProducerModule;

class DeliveryNoteObserver extends Observer
{
    public function events()
    {
        return [
            DeliveryNote::EVENT_CREATE => 'onDeliveryNoteCreate'
        ];
    }

    public function onDeliveryNoteCreate(DeliveryNoteCreateEvent $event)
    {
        $producerModule = ProducerModule::getInstance();
        $documentModule = DocumentModule::getInstance();

        if($producerModule->getSolver()->getConfig('delivery_note_automatic_validation')) {
            $documentModule->getManager()->validateDocument($event->deliveryNote);
        }
    }
}