<?php


namespace AutoAdmin\Bundle\Seo\Generator;


use AutoAdmin\Bundle\Core\Helper\DoctrineHelper;
use AutoAdmin\Bundle\Seo\Model\SeoContentInterface;
use AutoAdmin\Bundle\Seo\Model\SeoContentTranslationInterface;
use ReflectionClass;

abstract class AbstractGenerator implements GeneratorInterface
{
    public function getTypes(): array
    {
        return [self::TYPE_MANUAL_REGEN];
    }

    public function getSeoHolder($object): ?SeoContentTranslationInterface
    {
        $fqcn = DoctrineHelper::getClass($object);
        $refl = new ReflectionClass($fqcn);

        if (
            !$refl->implementsInterface(SeoContentInterface::class)
            && !$refl->implementsInterface(SeoContentTranslationInterface::class)
        ) {
            return null;
        }

        $seoHoldingObject = $refl->implementsInterface(SeoContentTranslationInterface::class) ?
            $object : $object->getCurrentTranslation();

        return $seoHoldingObject;
    }
}