<?php


namespace AutoAdmin\Bundle\Content\Context;


use AutoAdmin\Bundle\Seo\Model\SeoPage;
use AutoAdmin\Bundle\Seo\Schema\Model\Schema;
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 = null;
    protected ?Schema $schema = null;
    protected array $extras = [];

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

    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 getSchema(): ?Schema
    {
        return $this->schema;
    }

    public function setSchema(?Schema $schema): void
    {
        $this->schema = $schema;
    }

    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;
    }
}
