<?php

namespace AutoAdmin\Bundle\Content\Entity\Duplicators;

use AutoAdmin\Bundle\BrickBuilder\Builder\BuilderService;
use AutoAdmin\Bundle\Content\Service\DuplicatorService;
use AutoAdmin\Bundle\Media\Model\FileInterface;
use AutoAdmin\Bundle\Media\Service\MediaManipulator;
use Doctrine\ORM\EntityManagerInterface;

class FileDuplicator extends AbstractDuplicator
{
    protected MediaManipulator $mediaManipulator;
    public function __construct(
        DuplicatorService $duplicatorService,
        BuilderService $builderService,
        EntityManagerInterface $entityManager,
        MediaManipulator $mediaManipulator
    ) {
        parent::__construct($duplicatorService, $builderService, $entityManager);

        $this->mediaManipulator = $mediaManipulator;
    }

    /**
     * @return string[]
     */
    public function support(): array
    {
        return [
            FileInterface::class
        ];
    }

    /**
     * @param FileInterface $entity
     * @param FileInterface $duplicate
     *
     * @return FileInterface
     */
    public function duplicate($entity, $duplicate, $parent = null)
    {
        $duplicate = $this->mediaManipulator->duplicate($entity, $duplicate);

        $duplicate->setTitle($entity->getTitle());
        $duplicate->setFile($entity->getFile());
        $duplicate->setMimeType($entity->getMimeType());
        $duplicate->setSize($entity->getSize());
        $duplicate->setExtension($entity->getExtension());

        return $duplicate;
    }
}