<?php

namespace domain\Subscription\Subscription\Event;

use domain\Distribution\Distribution\Distribution;
use domain\Distribution\Distribution\Event\DistributionActiveEvent;
use domain\Order\Order\OrderModule;
use justcoded\yii2\eventlistener\observers\Observer;
use domain\Subscription\Subscription\SubscriptionModule;

class DistributionObserver extends Observer
{
    public function events()
    {
        return [
            Distribution::EVENT_ACTIVE => 'onDistributionActive'
        ];
    }

    public static function onDistributionActive(DistributionActiveEvent $event): void
    {
        $distribution = $event->distribution;
        $orderModule = OrderModule::getInstance();

        $orderModule->getManager()->createAllOrdersFromSubscriptions($event->distribution->date, $event->userAction);
    }
}