<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use JsonSerializable;

/**
 * Class ProductHistory
 * @package AppBundle\Entity
 * @ORM\Entity
 * @ORM\Table
 */
class ProductHistory extends MappedSuperclassBase implements JsonSerializable
{

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

    /**
     * @ORM\Column(type="integer")
     */
    private $amount = 1;


    /**
     * @ORM\Column(type="integer")
     */
    private $expectationAmount = 1;

    /**
     * @ORM\Column(type="integer")
     */
    private $remainingAmount = 0;


    /**
     * @ORM\Column(type="decimal", scale=2)
     */
    private $price;

    /**
     * @ManyToOne(targetEntity="Product", inversedBy="productHistories")
     * @JoinColumn(name="product_id", referencedColumnName="id")
     */
    private $product;

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

    /**
     * @param $id
     * @return ProductHistory
     */
    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }

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

        return $this;
    }

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

    /**
     * Set remainingAmount
     *
     * @param integer $remainingAmount
     *
     * @return ProductHistory
     */
    public function setRemainingAmount($remainingAmount)
    {
        $this->remainingAmount = $remainingAmount;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set product
     *
     * @param \AppBundle\Entity\Product $product
     *
     * @return ProductHistory
     */
    public function setProduct(\AppBundle\Entity\Product $product = null)
    {
        $this->product = $product;

        return $this;
    }

    /**
     * Get product
     *
     * @return \AppBundle\Entity\Product
     */
    public function getProduct()
    {
        return $this->product;
    }


    /**
     * Set expectationAmount
     *
     * @param integer $expectationAmount
     *
     * @return ProductHistory
     */
    public function setExpectationAmount($expectationAmount)
    {
        $this->expectationAmount = $expectationAmount;

        return $this;
    }

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

    /**
     * Specify data which should be serialized to JSON
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
     * @return mixed data which can be serialized by <b>json_encode</b>,
     * which is a value of any type other than a resource.
     * @since 5.4.0
     */
    function jsonSerialize()
    {
        return array(
            'id' => $this->id,
            'amount' => $this->amount,
            'creationDate' => $this->getCreationDate(),
            'remainingAmount' => $this->remainingAmount,
            'price' => $this->price,
            'productId' => $this->product->id,
            'productName' => $this->product->name
        );
    }
}
