<?php

namespace AutoAdmin\Bundle\Content\Entity\Duplicators;

use AutoAdmin\Bundle\BrickBuilder\Builder\BuilderService;
use AutoAdmin\Bundle\Content\Entity\Interfaces\DuplicatorInterface;
use AutoAdmin\Bundle\Content\Service\DuplicatorService;
use Doctrine\ORM\EntityManagerInterface;
use ReflectionClass;

abstract class AbstractDuplicator implements DuplicatorInterface
{
    protected DuplicatorService $duplicatorService;
    protected BuilderService $builderService;
    protected EntityManagerInterface $entityManager;

    public function __construct(
        DuplicatorService $duplicatorService,
        BuilderService $builderService,
        EntityManagerInterface $entityManager
    ) {
        $this->duplicatorService = $duplicatorService;
        $this->builderService = $builderService;
        $this->entityManager = $entityManager;
    }

    public function isSupported($entity): bool
    {
        $reflection = new ReflectionClass($entity);

        $diff = array_intersect($reflection->getInterfaceNames(), $this->support());

        return !empty($diff);
    }
}
