<?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 AutoAdmin\Bundle\Content\Model\PublishableInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
 * Class Page
 *
 * @package AutoAdmin\Bundle\Entity\Content
 */
#[ORM\MappedSuperclass]
#[BreadcrumbsHierarchy(parentPath: 'parent')]
abstract class Page extends Content implements PublishableInterface, PageInterface, SelfHierarchyInterface
{
    use PublishableTrait;
    use HiddenBreadcrumbTrait;
    use SelfHierarchyTrait {
        SelfHierarchyTrait::__construct as protected __selfHierarchyTraitConstruct;
    }

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

    #[ORM\OneToMany(mappedBy: 'parent', targetEntity: PageInterface::class)]
    private 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;
    }
}
