<?php

namespace Webkul\DamBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

/**
 * AssetCategory
 */
class AssetCategory extends \BaseCategory implements \CategoryInterface
{
    /**
     * @var integer
     */
    protected $id;

    /**
     * @var string
     */
    protected $code;

    /**
     * @var \DateTime
     */
    protected $created;

    /**
     * @var integer
     */
    protected $root;

    /**
     * @var integer
     */
    protected $level;

    /**
     * @var integer
     */
    protected $left;

    /**
     * @var integer
     */
    protected $right;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    protected $translations;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    protected $children;

    /**
     * @var CategoryInterface
     */
    protected $parent;

    /**
     * Used locale to override Translation listener's locale
     * this is not a mapped field of entity metadata, just a simple property
     *
     * @var string
     */
    protected $locale;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->translations = new \Doctrine\Common\Collections\ArrayCollection();
        $this->children = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set code
     *
     * @param string $code
     *
     * @return AssetCategory
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

    /**
     * Get code
     *
     * @return string
     */
    public function getCode()
    {
        return $this->code;
    }

    /**
     * Set created
     *
     * @param \DateTime $created
     *
     * @return AssetCategory
     */
    public function setCreated($created)
    {
        $this->created = $created;

        return $this;
    }

    /**
     * Get created
     *
     * @return \DateTime
     */
    public function getCreated()
    {
        return $this->created;
    }

    /**
     * Set root
     *
     * @param integer $root
     *
     * @return AssetCategory
     */
    public function setRoot($root)
    {
        $this->root = $root;

        return $this;
    }

    /**
     * Get root
     *
     * @return integer
     */
    public function getRoot()
    {
        return $this->root;
    }

    /**
     * Set level
     *
     * @param integer $level
     *
     * @return AssetCategory
     */
    public function setLevel($level)
    {
        $this->level = $level;

        return $this;
    }

    /**
     * Get level
     *
     * @return integer
     */
    public function getLevel()
    {
        return $this->level;
    }

    /**
     * Set left
     *
     * @param integer $left
     *
     * @return AssetCategory
     */
    public function setLeft($left)
    {
        $this->left = $left;

        return $this;
    }

    /**
     * Get left
     *
     * @return integer
     */
    public function getLeft()
    {
        return $this->left;
    }

    /**
     * Set right
     *
     * @param integer $right
     *
     * @return AssetCategory
     */
    public function setRight($right)
    {
        $this->right = $right;

        return $this;
    }

    /**
     * Get right
     *
     * @return integer
     */
    public function getRight()
    {
        return $this->right;
    }

   
   

    /**
     * Remove translation
     *
     * @param \Webkul\DamBundle\Model\AssetCategoryTranslationInterface $translation
     */
    public function removeTranslation(\Webkul\DamBundle\Model\AssetCategoryTranslationInterface $translation)
    {
        $this->translations->removeElement($translation);
    }

    /**
     * Remove translation
     *
     */
    public function removeTranslations()
    {
        $this->translations = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get translations
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getTranslations()
    {
        // if()
        return $this->translations;
    }

    /**
     * Add child
     *
     * @param CategoryInterface $child
     *
     * @return AssetCategory
     */
    public function addChild(\CategoryInterface $child)
    {
        $this->children[] = $child;

        return $this;
    }

    /**
     * Remove child
     *
     * @param CategoryInterface $child
     */
    public function removeChild(\CategoryInterface $child)
    {
        $this->children->removeElement($child);
    }

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

    /**
     * Set parent
     *
     * @param CategoryInterface $parent
     *
     * @return AssetCategory
     */
    public function setParent(\CategoryInterface $parent = null)
    {
        $this->parent = $parent;
       
        return $this;
    }

    /**
     * Get parent
     *
     * @return CategoryInterface
     */
    public function getParent()
    {
        return $this->parent;
    }

    public function setLocale($locale)
    {
        $this->locale = $locale;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getTranslation($locale = null)
    {
        $locale = ($locale) ? $locale : $this->locale;
        if (null === $locale) {
            return null;
        }
        foreach ($this->getTranslations() as $translation) {
            if ($translation->getLocale() == $locale) {
                return $translation;
            }
        }

        $translationClass = $this->getTranslationFQCN();
        $translation = new $translationClass();
        $translation->setLocale($locale);
        $translation->setForeignKey($this);
        $this->addTranslation($translation);

        return $translation;
    }

    
    public function addTranslation($translation)
    {
        if (!$this->translations->contains($translation)) {
            $this->translations->add($translation);
        }
        return $this;
    }

    

    /**
     * {@inheritdoc}
     */
    public function getTranslationFQCN()
    {
        return 'Webkul\DamBundle\Entity\AssetCategoryTranslation';
    }

    /**
     * Get label
     *
     * @return string
     */
    public function getLabel()
    {
        $translated = ($this->getTranslation()) ? $this->getTranslation()->getLabel() : null;

        return ($translated !== '' && $translated !== null) ? $translated : '['.$this->getCode().']';
    }

    /**
     * Set label
     *
     * @param string $label
     *
     * @return CategoryInterface
     */
    public function setLabel($label)
    {
        $this->getTranslation()->setLabel($label);

        return $this;
    }

    /**
     * Returns the channels linked to the category
     *
     * @return ArrayCollection
     */
    public function getChannels()
    {
        return $this->channels;
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->getLabel();
    }

    /**
     * {@inheritdoc}
     */
    public function getReference()
    {
        return $this->code;
    }

    /**
     * {@inheritdoc}
     */
    public function hasChildren()
    {
        return count($this->getChildren()) > 0;
    }


    /**
     * {@inheritdoc}
     */
    public function isRoot()
    {
        return (null === $this->getParent());
    }
    
    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $asset;


    /**
     * Add asset
     *
     * @param \Webkul\DamBundle\Entity\Asset $asset
     *
     * @return AssetCategory
     */
    public function addAsset(\Webkul\DamBundle\Entity\Asset $asset)
    {
        $this->asset[] = $asset;

        return $this;
    }

    /**
     * Remove asset
     *
     * @param \Webkul\DamBundle\Entity\Asset $asset
     */
    public function removeAsset(\Webkul\DamBundle\Entity\Asset $asset)
    {
        $this->asset->removeElement($asset);
    }

    /**
     * Get asset
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAsset()
    {
        return $this->asset;
    }
}
