<?php declare(strict_types=1);

namespace App\Engine\Navigation;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Navigation
{

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;
    #[ORM\Column(type: 'integer')]
    private int $priority = 0;
    #[ORM\Column(type: 'string', length: 180, nullable: true)]
    private ?string $url = null;
    #[ORM\Column(type: 'string')]
    private string $title = "";
    #[ORM\Column(type: 'string', enumType: NavigationSection::class)]
    private NavigationSection $section = NavigationSection::HeaderMain;
    #[ORM\Column(type: 'boolean')]
    private bool $enabled = true;
    #[ORM\Column(type: 'boolean')]
    private bool $targetBlank = false;
    #[ORM\ManyToOne(targetEntity: \App\Engine\Page\Page::class, fetch: 'EAGER')]
    #[ORM\JoinColumn(nullable: true)]
    private ?\App\Engine\Page\Page $page = null;
    #[ORM\ManyToOne(targetEntity: self::class, inversedBy: "children", fetch: 'EAGER')]
    #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
    private ?Navigation $parent = null;
    #[ORM\OneToMany(targetEntity: self::class, mappedBy: "parent", fetch: 'EAGER')]
    private \Doctrine\Common\Collections\Collection $children;

    public function __construct()
    {
        $this->children = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getPriority(): int
    {
        return $this->priority;
    }

    public function setPriority(int $priority): self
    {
        $this->priority = $priority;
        return $this;
    }

    public function getUrl(): ?string
    {
        return $this->page?->getUrl() ?? $this->url;
    }

    public function setUrl(?string $url): self
    {
        if ($url) {
            $url = \App\Engine\Utills\StringHelpers::sanitizeUrlAsAbsoulutePath($url);
        }

        $this->url = $url;
        return $this;
    }

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

    public function setTitle(string $title): self
    {
        $this->title = $title;
        return $this;
    }

    public function getEnabled(): bool
    {
        return $this->enabled;
    }

    public function setEnabled(bool $enabled): self
    {
        $this->enabled = $enabled;
        return $this;
    }

    public function getTargetBlank(): bool
    {
        return $this->targetBlank;
    }

    public function setTargetBlank(bool $targetBlank): self
    {
        $this->targetBlank = $targetBlank;
        return $this;
    }

    public function getSection(): NavigationSection
    {
        return $this->section;
    }

    public function setSection(NavigationSection $section): self
    {
        $this->section = $section;
        return $this;
    }

    public function getPage(): ?\App\Engine\Page\Page
    {
        return $this->page;
    }

    public function setPage(?\App\Engine\Page\Page $page): self
    {
        $this->page = $page;
        return $this;
    }

    public function getParent(): ?Navigation
    {
        return $this->parent;
    }

    public function setParent(?Navigation $parent): void
    {
        $this->parent = $parent;
    }

    /**
     * @return \Doctrine\Common\Collections\Collection<self>
     */
    public function getChildren(): \Doctrine\Common\Collections\Collection
    {
        return $this->children;
    }

}