<?php

namespace Lc\SovBundle\Twig;

use Lc\SovBundle\Component\MetaComponent;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class MetaTwigExtension extends AbstractExtension
{
    protected MetaComponent $metaComponent;

    public function __construct(MetaComponent $metaComponent)
    {
        $this->metaComponent = $metaComponent;
    }

    public function getFunctions()
    {
        return [
                new TwigFunction('sov_meta_title', [$this, 'getMetaTitle']),
                new TwigFunction('sov_meta_description', [$this, 'getMetaDescription']),
                new TwigFunction('sov_opengraph_title', [$this, 'getOpengraphTitle']),
                new TwigFunction('sov_opengraph_description', [$this, 'getOpengraphDescription']),
                new TwigFunction('sov_opengraph_image', [$this, 'getOpengraphImage']),
        ];
    }

    public function getFilters()
    {
        return [];
    }

    public function getMetaTitle($entity): ?string
    {
        return $this->metaComponent->getMetaTitle($entity);
    }

    public function getMetaDescription($entity): ?string
    {
        return $this->metaComponent->getMetaDescription($entity);
    }

    public function getOpenGraphTitle($entity): ?string
    {
        return $this->metaComponent->getOpenGraphTitle($entity);
    }

    public function getOpenGraphDescription($entity): ?string
    {
        return $this->metaComponent->getOpenGraphDescription($entity);
    }

    public function getOpenGraphImage($entity): ?string
    {
        return $this->metaComponent->getOpenGraphImage($entity);
    }
}