<?php

declare(strict_types=1);

namespace External\HannahBundle\DependencyInjection\Compiler;

use KupShop\DropshipBundle\Transfer\BaseLinkerTransfer;
use KupShop\ReturnsBundle\EventListener\ReturnsEventListener;
use KupShop\ReturnsBundle\View\CreateReturnView;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class UnregisterUnwantedServicesPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $this->updateReturns($container);
        $this->updateDropship($container);
    }

    private function updateReturns(ContainerBuilder $container): void
    {
        if (findModule(\Modules::RETURNS)) {
            return;
        }

        // musim odebrat predefinovane definice kvuli monobrandum, ktere nemaji aktivni modul vratky
        $container->removeDefinition(ReturnsEventListener::class);
        $container->removeDefinition(CreateReturnView::class);
    }

    private function updateDropship(ContainerBuilder $container): void
    {
        if (findModule(\Modules::DROPSHIP)) {
            return;
        }

        $container->removeDefinition(BaseLinkerTransfer::class);
    }
}
