<?php
/**
 * @license MIT
 *
 * Modified by RTM Business on 16-December-2024 using {@see https://github.com/BrianHenryIE/strauss}.
 */

declare(strict_types=1);

namespace RtmMailVendor\Dependencies\Doctrine\ORM\Tools\Console\EntityManagerProvider;

use RtmMailVendor\Dependencies\Doctrine\Deprecations\Deprecation;
use RtmMailVendor\Dependencies\Doctrine\ORM\EntityManagerInterface;
use RtmMailVendor\Dependencies\Doctrine\ORM\Tools\Console\EntityManagerProvider;
use RtmMailVendor\Dependencies\Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use RtmMailVendor\Dependencies\Symfony\Component\Console\Helper\HelperSet;

use function assert;

/** @deprecated This class will be removed in ORM 3.0 without replacement. */
final class HelperSetManagerProvider implements EntityManagerProvider
{
    /** @var HelperSet */
    private $helperSet;

    public function __construct(HelperSet $helperSet)
    {
        $this->helperSet = $helperSet;

        Deprecation::trigger(
            'doctrine/orm',
            'https://github.com/doctrine/orm/issues/8327',
            'Use of a HelperSet and the HelperSetManagerProvider is deprecated and will be removed in ORM 3.0'
        );
    }

    public function getManager(string $name): EntityManagerInterface
    {
        if ($name !== 'default') {
            throw UnknownManagerException::unknownManager($name, ['default']);
        }

        return $this->getDefaultManager();
    }

    public function getDefaultManager(): EntityManagerInterface
    {
        $helper = $this->helperSet->get('entityManager');

        assert($helper instanceof EntityManagerHelper);

        return $helper->getEntityManager();
    }
}
