<?php

namespace AutoAdmin\Bundle\Core\Doctrine;

use AutoAdmin\Bundle\DependencyInjection\AutoAdminExtension;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class DoctrineInterfaceAliasResolver
{
    public function __construct(
        #[Autowire('%'.AutoAdminExtension::CONTAINER_PARAM_DOCTRINE_ALIASES.'%')]
        protected array $aliases,
        protected EntityManagerInterface $em,
    ) {
    }

    public function hasClass(string $aliasInterface): bool
    {
        return !empty($this->aliases[$aliasInterface]);
    }

    public function getClass(string $aliasInterface): string
    {
        return $this->aliases[$aliasInterface]
            ?? throw new \Exception('Could not find doctrine alias for "'.$aliasInterface.'"');
    }
}
