<?php

namespace AppBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
use JsonSerializable;

use Symfony\Component\Validator\Constraints as Assert;
/**
 * @ORM\Entity
 * @ORM\Table(name="product")
 */
class Product extends MappedSuperclassBase implements JsonSerializable
{

    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=100)
     */
    private $name;


    /**
     * @ManyToOne(targetEntity="ProductGroup", inversedBy="products")
     * @JoinColumn(name="product_group_id", referencedColumnName="id")
     */
    private $productGroup;


    /**
     * @OneToMany(targetEntity="ProductHistory", mappedBy="product",cascade={"all"})
     */
    private $productHistories;

    /**
     * @OneToOne(targetEntity="AppBundle\Entity\Mac", inversedBy="product")
     * @JoinColumn(name="mac_id", referencedColumnName="id")
     */
    private $mac;

    /**
     * @OneToOne(targetEntity="AppBundle\Entity\Person", inversedBy="product")
     * @JoinColumn(name="person_id", referencedColumnName="id")
     */
    private $person;

    /**
     * @Column(type="datetime")
     */
    private $startDate;

    /**
     * @Column(type="datetime")
     */
    private $endDate;

    private $price;

    private $inputAmount;
    private $outputAmount;


    private $amount;

    public function __construct()
    {
        parent::__construct();
        $this->productHistories = new ArrayCollection();
        $this->setStartDate(new \DateTime());
        $this->setEndDate(new \DateTime());
    }

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

    /**
     * Set name
     *
     * @param string $name
     *
     * @return Product
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

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


    /**
     * Set productGroup
     *
     * @param \AppBundle\Entity\ProductGroup $productGroup
     *
     * @return Product
     */
    public function setProductGroup(\AppBundle\Entity\ProductGroup $productGroup = null)
    {
        $this->productGroup = $productGroup;

        return $this;
    }

    /**
     * Get productGroup
     *
     * @return \AppBundle\Entity\ProductGroup
     */
    public function getProductGroup()
    {
        return $this->productGroup;
    }


    /**
     * Add productHistory
     *
     * @param \AppBundle\Entity\ProductHistory $productHistory
     *
     * @return Product
     */
    public function addProductHistory(\AppBundle\Entity\ProductHistory $productHistory)
    {
        $this->productHistories[] = $productHistory;

        return $this;
    }

    /**
     * Remove productHistory
     *
     * @param \AppBundle\Entity\ProductHistory $productHistory
     */
    public function removeProductHistory(\AppBundle\Entity\ProductHistory $productHistory)
    {
        $this->productHistories->removeElement($productHistory);
    }

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


    public function __toString()
    {
        if ($this->getName() == null)
            return $this->getId();
        return $this->getName();
    }

    public function jsonSerialize()
    {
        return array(
            'id' => $this->id,
            'name' => $this->name,
        );
    }

    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * Set amount
     *
     * @param integer $amount
     *
     * @return Product
     */
    public function setAmount($amount)
    {
        $this->amount = $amount;

        return $this;
    }

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


    /**
     * Set price
     *
     * @param string $price
     *
     * @return Product
     */
    public function setPrice($price)
    {
        $this->price = $price;

        return $this;
    }

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

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

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

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

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

    /**
     * Set mac
     *
     * @param \AppBundle\Entity\Mac $mac
     *
     * @return Product
     */
    public function setMac(\AppBundle\Entity\Mac $mac = null)
    {
        $this->mac = $mac;

        return $this;
    }

    /**
     * Get mac
     *
     * @return \AppBundle\Entity\Mac
     */
    public function getMac()
    {
        return $this->mac;
    }

    /**
     * Set startDate
     *
     * @param \DateTime $startDate
     *
     * @return Product
     */
    public function setStartDate($startDate)
    {
        $this->startDate = $startDate;

        return $this;
    }

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

    /**
     * Set endDate
     *
     * @param \DateTime $endDate
     *
     * @return Product
     */
    public function setEndDate($endDate)
    {
        $this->endDate = $endDate;

        return $this;
    }

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

    /**
     * Set person
     *
     * @param \AppBundle\Entity\Person $person
     *
     * @return Product
     */
    public function setPerson(\AppBundle\Entity\Person $person = null)
    {
        $this->person = $person;

        return $this;
    }

    /**
     * Get person
     *
     * @return \AppBundle\Entity\Person
     */
    public function getPerson()
    {
        return $this->person;
    }
}
