<?php

namespace AutoAdmin\Bundle\Content\Duplicator;

use AutoAdmin\Bundle\Content\Hierarchy\Model\Interfaces\SelfHierarchyInterface;

class SelfHierarchyDuplicator extends AbstractDuplicator
{
    /**
     * @return string[]
     */
    public function supportInterfaces(): array
    {
        return [
            SelfHierarchyInterface::class,
        ];
    }

    /**
     * @param SelfHierarchyInterface $entity
     * @param SelfHierarchyInterface $duplicate
     *
     * @return SelfHierarchyInterface
     */
    public function duplicate(object $entity, object $duplicate): object
    {
        $children = $entity->getChildren();

        foreach ($children as $child) {
            $duplicateChild = $this->duplicatorManager->duplicate($child);
            $duplicate->addChild($duplicateChild);
        }

        return $duplicate;
    }
}
