<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RxConnexionBundle\Entity\Base\BaseEntity;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\MaxDepth;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ItemPackageRepository")
 * @ORM\Table(name="item_package")
 */

class ItemPackageEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="code", type="string", nullable=true)
     */
    protected $code;

    /**
     * @ORM\Column(name="description", type="string")
     */
    protected $description;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\ItemPackageItemEntity", mappedBy="itemPackage", orphanRemoval=true, cascade={"persist", "remove"})
     */
    protected $itemPackageItems;

    /**
     * @ORM\Column(name="is_deleted", type="boolean")
     */
    protected $isDeleted;

    /**
     * Set createdAt
     *
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        parent::setCreatedAtValue();
        $this->isDeleted = 0;
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					User Defined Setters and Getters													  */
    /*--------------------------------------------------------------------------------------------------------*/

    /**
     * Get startDateAsString
     *
     * @return string
     */
    public function getStartDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->startDate) ? date('m/d/Y', strtotime($dttst->transform($this->startDate))) : '';
    }

    /**
     * Get endDateAsString
     *
     * @return string
     */
    public function getEndDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->endDate) ? date('m/d/Y', strtotime($dttst->transform($this->endDate))) : '';
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					Setters and Getters																	  */
    /*--------------------------------------------------------------------------------------------------------*/
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->itemPackageItems = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

        return $this;
    }

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

    /**
     * Set description
     *
     * @param string $description
     *
     * @return ItemPackageEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set isDeleted
     *
     * @param boolean $isDeleted
     *
     * @return ItemPackageEntity
     */
    public function setIsDeleted($isDeleted)
    {
        $this->isDeleted = $isDeleted;

        return $this;
    }

    /**
     * Get isDeleted
     *
     * @return boolean
     */
    public function getIsDeleted()
    {
        return $this->isDeleted;
    }

    /**
     * Add itemPackageItem
     *
     * @param \RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem
     *
     * @return ItemPackageEntity
     */
    public function addItemPackageItem(\RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem)
    {
        $itemPackageItem->setItemPackage($this);
        $this->itemPackageItems[] = $itemPackageItem;

        return $this;
    }

    /**
     * Remove itemPackageItem
     *
     * @param \RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem
     */
    public function removeItemPackageItem(\RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem)
    {
        $this->itemPackageItems->removeElement($itemPackageItem);
    }

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