<?php

namespace common\logic\Subscription\Subscription\Event;

use common\logic\Distribution\Distribution\Event\DistributionActiveEvent;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Subscription\Subscription\Module\SubscriptionModule;
use justcoded\yii2\eventlistener\observers\Observer;

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

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

        $subscriptionModule->getOrderManager()->createAllOrdersFromSubscriptions($distribution->date);
    }
}