<?php

namespace AutoAdmin\Bundle\Content\Duplicator;

use AutoAdmin\Bundle\Content\Duplicator\Enum\StringDuplicateModeEnum;
use AutoAdmin\Bundle\Content\Model\SlugAdminInterface;

class SlugAdminDuplicator extends AbstractDuplicator
{
    /**
     * @return string[]
     */
    public function supportInterfaces(): array
    {
        return [
            SlugAdminInterface::class,
        ];
    }

    /**
     * @param SlugAdminInterface $entity
     * @param SlugAdminInterface $duplicate
     *
     * @return SlugAdminInterface
     */
    public function duplicate(object $entity, object $duplicate): object
    {
        $currentSlugAdmin = $entity->getSlugAdmin();
        if (!empty($currentSlugAdmin)) {
            // not normalized, so handle both cases
            if (str_contains($currentSlugAdmin, $this->suffixes->getSeparator(StringDuplicateModeEnum::KEBAB))) {
                $dupedSlug = $this->suffixes->duplicate($currentSlugAdmin, StringDuplicateModeEnum::KEBAB);
            } else {
                $dupedSlug = $this->suffixes->duplicate($currentSlugAdmin, StringDuplicateModeEnum::SNAKE);
            }

            $duplicate->setSlugAdmin($dupedSlug);
        }

        return $duplicate;
    }
}
