<?php

namespace AutoAdmin\Bundle\Content\Duplicator;

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 supportInterfaces(): array
    {
        return [
            FileInterface::class
        ];
    }

    /**
     * @param FileInterface $entity
     * @param FileInterface $duplicate
     *
     * @return FileInterface
     */
    public function duplicate(object $entity, object $duplicate, ?object $parent = null): object
    {
        $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;
    }
}
