<?php

namespace AutoAdmin\Bundle\Content\Entity\Duplicators;

use AutoAdmin\Bundle\Content\Model\TranslatableInterface;

class TranslatableDuplicator extends AbstractDuplicator
{
    /**
     * @return string[]
     */
    public function support(): array
    {
        return [
            TranslatableInterface::class
        ];
    }

    /**
     * @param TranslatableInterface $entity
     * @param TranslatableInterface $duplicate
     *
     * @return TranslatableInterface
     */
    public function duplicate($entity, $duplicate, $parent = null)
    {
        $translations = $entity->getTranslations();
        foreach ($translations as $translation) {
            $duplicateTranslation = $this->duplicatorService->duplicate($translation);
            $duplicate->addTranslation($duplicateTranslation);
        }

        $duplicate->setCurrentTranslation($duplicate->getTranslations()->first());

        return $duplicate;
    }
}