<?php


namespace AutoAdmin\Bundle\Content\Context;


use AutoAdmin\Bundle\Seo\Model\SeoPage;
use Exception;
use Symfony\Component\HttpFoundation\RequestStack;

class ContentContext
{

    /**
     * Main request context, usually a page
     */
    protected ?object $mainContent = null;
    protected RequestStack $requestStack;
    protected ?SeoPage $seoPage;
    protected array $extras = [];

    public function __construct(RequestStack $requestStack)
    {
        $this->requestStack = $requestStack;
        $this->seoPage = new SeoPage();
    }

    public function getMainContent(): ?object
    {
        return $this->mainContent;
    }

    public function setMainContent(object $mainContent): void
    {
        $this->mainContent = $mainContent;
    }

    public function getSeoPage(): ?SeoPage
    {
        return $this->seoPage;
    }

    public function setSeoPage(?SeoPage $seoPage): void
    {
        $this->seoPage = $seoPage;
    }



    public function getExtra(string $name)
    {
        return $this->extras[$name] ?? null;
    }

    public function setExtra(string $name, $value, $throwIfReplace = false)
    {
        if (array_key_exists($name, $this->extras) && $throwIfReplace !== false) {
            throw new Exception('Could not replace value without explicit intention.');
        }

        return $this->extras[$name] = $value;
    }

    public function getExtras(): array
    {
        return $this->extras;
    }

    public function setExtras(array $extras): void
    {
        $this->extras = $extras;
    }
}
