<?php

namespace AutoAdmin\Bundle\Content\Duplicator;

use AutoAdmin\Bundle\Content\Entity\Interfaces\MenuItemInterface;

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

    /**
     * @param MenuItemInterface $entity
     * @param MenuItemInterface $duplicate
     *
     * @return MenuItemInterface
     */
    public function duplicate(object $entity, object $duplicate): object
    {
        foreach ($entity->getChildren() as $child) {
            /** @var MenuItemInterface $dupChild */
            $dupChild = $this->duplicatorManager->duplicate($child);
            $dupChild->setMenu($duplicate);
            $duplicate->addChild($dupChild);
        }
        $duplicate->setDisplay($entity->isDisplay());
        $duplicate->setType($entity->getType());
        $duplicate->setUri($entity->getUri());
        $duplicate->setWrapperAttributes($entity->getWrapperAttributes());
        $duplicate->setLinkAttributes($entity->getLinkAttributes());
        $duplicate->setChildrenAttributes($entity->getChildrenAttributes());
        if ($entity->getContentReference() !== null) {
            $duplicate->setContentReference($this->duplicatorManager->duplicate($entity->getContentReference()));
        }

        return $duplicate;
    }
}
