<?php

namespace App\Model\Entities\Templates;

use App\Model\Entities\BaseNamedRecord;
use App\Model\Entities\Security\User;
use App\Model\Interfaces\ICommonRecord;
use App\Model\Interfaces\ISite;
use App\Model\Interfaces\ITemplate;
use Doctrine\ORM\Mapping as ORM;


/**
 * @ORM\Entity
 * @ORM\InheritanceType(value="SINGLE_TABLE")
 * @ORM\Table("template")
 */
abstract class BaseTemplate extends BaseNamedRecord implements ICommonRecord, ITemplate
{
    /**
     * @ORM\Column(type="string", nullable=true)
     */
    protected $description;

    /**
     * @var BaseTemplate
     * @ORM\ManyToOne(targetEntity="BaseTemplate")
     * @ORM\JoinColumn(nullable=true)
     */
    protected $parentTemplate;

    /**
     * @var  ISite
     * @ORM\ManyToOne(targetEntity="App\Model\Entities\PortalSite")
     */
    protected $site;

    public function __construct(User $createdBy, ISite $site)
    {
        parent::__construct($createdBy);
        $this->site = $site;
    }

    /**
     * @return ISite
     */
    public function getSite() : ISite
    {
        return $this->site;
    }

    /**
     * @return mixed
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @param mixed $description
     */
    public function setDescription($description)
    {
        $this->description = $description;
    }

    /**
     * @return ITemplate
     */
    public function getParentTemplate() : ITemplate
    {
        return $this->parentTemplate;
    }

    /**
     * @param ITemplate $parentTemplate
     */
    public function setParentTemplate(ITemplate $parentTemplate)
    {
        $this->parentTemplate = $parentTemplate;
    }

    public function hasParentTemplate() : bool
    {
        return ($this->parentTemplate !== null);
    }

}