<?php


namespace AutoAdmin\Bundle\Content\Entity;

use AutoAdmin\Bundle\Content\Breadcrumbs\Model\Attributes\BreadcrumbsHierarchy;
use AutoAdmin\Bundle\Content\Entity\Traits\HiddenBreadcrumbTrait;
use AutoAdmin\Bundle\Content\Entity\Traits\PublishableTrait;
use AutoAdmin\Bundle\Content\Hierarchy\Model\Interfaces\SelfHierarchyInterface;
use AutoAdmin\Bundle\Content\Hierarchy\Model\Traits\SelfHierarchyTrait;
use AutoAdmin\Bundle\Content\Model\PageInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\MappedSuperclass]
#[BreadcrumbsHierarchy(parentPath: 'parent')]
abstract class Page extends SeoContent implements
    PageInterface,
    SelfHierarchyInterface
{
    use PublishableTrait;

    use HiddenBreadcrumbTrait;
    use SelfHierarchyTrait {
        SelfHierarchyTrait::__construct as protected __selfHierarchyTraitConstruct;
    }

    #[ORM\ManyToOne(targetEntity: PageInterface::class, inversedBy: 'children')]
    protected ?SelfHierarchyInterface $parent = null;

    #[ORM\OneToMany(mappedBy: 'parent', targetEntity: PageInterface::class)]
    protected Collection $children;

    #[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
    protected bool $homepage = false;

    public function __construct()
    {
        parent::__construct();
        $this->__selfHierarchyTraitConstruct();
    }

    public function isHomepage(): bool
    {
        return $this->homepage;
    }

    public function setHomepage(bool $homepage): self
    {
        $this->homepage = $homepage;

        return $this;
    }
}
