<?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 $parent = null): object
    {
        if ($parent instanceof MenuItemInterface) {
            $duplicate->setMenu($parent);
        }
        foreach ($entity->getChildren() as $child) {
            $duplicate->addChild($this->duplicatorService->duplicate($child, $duplicate));
        }
        $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->duplicatorService->duplicate($entity->getContentReference()));
        }

        return $duplicate;
    }
}
