<?php


namespace AutoAdmin\Bundle\Seo\Model;


use AutoAdmin\Bundle\Seo\Schema\Model\SchemaStack;
use Doctrine\Common\Collections\ArrayCollection;

class SeoPage
{
    protected ?string $title = null;

    /**
     * @var ArrayCollection<Meta>
     */
    protected ArrayCollection $metas;

    protected ArrayCollection $openGraphMetas;

    protected ArrayCollection $responseHeaders;

    protected SchemaStack $schemaStack;// programmatically-generated schema model

    /**
     * @var array<string>
     */
    protected array $structuredData = [];// administration-provided jsonld strings

    protected ?string $canonical = null;

    protected ?array $alternates = null;

    public function __construct()
    {
        $this->metas = new ArrayCollection();
        $this->schemaStack = new SchemaStack();
        $this->openGraphMetas = new ArrayCollection();
        $this->responseHeaders = new ArrayCollection();
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function setTitle($title): void
    {
        $this->title = $title;
    }

    /**
     * @return ArrayCollection<Meta>
     */
    public function getMetas(): ArrayCollection
    {
        return $this->metas;
    }

    public function setMetas(ArrayCollection $metas): void
    {
        $this->metas = $metas;
    }

    public function addMeta(Meta $meta): void
    {
        $this->metas->add($meta);
    }

    public function removeMeta(Meta $meta): void
    {
        $this->metas->remove($this->metas->indexOf($meta));
    }

    public function getOpenGraphMetas(): ArrayCollection
    {
        return $this->openGraphMetas;
    }

    public function setOpenGraphMetas(ArrayCollection $metas): void
    {
        $this->openGraphMetas = $metas;
    }

    public function addOpenGraphMeta(Meta $meta): void
    {
        $this->openGraphMetas->add($meta);
    }

    public function removeOpenGraphMeta(Meta $meta): void
    {
        $this->openGraphMetas->remove($this->openGraphMetas->indexOf($meta));
    }

    public function getResponseHeaders(): ArrayCollection
    {
        return $this->responseHeaders;
    }

    public function setResponseHeaders($responseHeaders): void
    {
        $this->responseHeaders = $responseHeaders;
    }

    public function addResponseHeader(Header $header): void
    {
        $this->responseHeaders->add($header);
    }

    public function removeResponseHeader(Header $header): void
    {
        $this->responseHeaders->remove($this->responseHeaders->indexOf($header));
    }

    public function getSchemaStack(): ?SchemaStack
    {
        return $this->schemaStack;
    }

    public function setSchemaStack(?SchemaStack $schemaStack): void
    {
        $this->schemaStack = $schemaStack;
    }

    public function getStructuredData(): array
    {
        return $this->structuredData;
    }

    public function setStructuredData(array $structuredData): void
    {
        $this->structuredData = $structuredData;
    }

    public function appendStructuredData($element, $first = false): void
    {
        if ($first) {
            array_unshift($this->structuredData, $element);
        } else {
            $this->structuredData[] = $element;
        }
    }

    public function getCanonical()
    {
        return $this->canonical;
    }

    public function setCanonical($canonical): void
    {
        $this->canonical = $canonical;
    }

    public function getAlternates()
    {
        return $this->alternates;
    }

    public function setAlternates($alternates): void
    {
        $this->alternates = $alternates;
    }
}
