<?php

namespace AutoAdmin\Bundle\Content\Duplicator;

use AutoAdmin\Bundle\Media\Attributes\LinkedMedia;

class LinkedMediaDuplicator extends AbstractDuplicator
{
    public function supportAttributes(): array
    {
        return [
            LinkedMedia::class,
        ];
    }

    public function duplicate(object $entity, object $duplicate, ?object $parent = null): object
    {
        $props = $this->getPropertiesWithAttribute($entity, LinkedMedia::class);
        /** @var \ReflectionProperty $brickBuilderProp */
        foreach ($props as $prop) {
            $value = $prop->getValue($entity);
            if ($value !== null) {
                $prop->setValue($duplicate, $prop->getValue($entity));
            }
        }

        return $duplicate;
    }
}
