<?php

namespace App\Entity\Model;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Gedmo\Timestampable\Timestampable;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Product
 *
 * @ORM\Table(name="product", uniqueConstraints={@ORM\UniqueConstraint(name="product_unique", columns={
 *     "reference",
 *     "empresa_id"
 * })}))
 * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Product implements \JsonSerializable, Timestampable
{
    //use TimestampableEntity;

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

    /**
     * @var string
     *
     * @ORM\Column(name="slug", type="string", length=32, nullable=true, unique=true)
     */
    private $slug;

    /**
     * @var string
     *
     * @ORM\Column(name="reference", type="string", length=25)
     * @Assert\NotBlank()
     */
    private $reference;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="string", length=255, nullable=true)
     */
    private $description;

    /**
     * @var string
     *
     * @ORM\Column(name="price", type="decimal", precision=20, scale=6)
     * @Assert\NotBlank()
     */
    private $price;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Model\Item", mappedBy="product")
     */
    private $items;

/**
 * @var string|null
 *
 * @ORM\Column(name="price2", type="decimal", precision=20, scale=6, nullable=true)
 */
private $price2;    
    

    /**
 * @ORM\OneToOne(
 *     targetEntity="App\Entity\Model\InventarioExistencia",
 *     mappedBy="product"
 * )
 */
private $inventarioExistencia;




    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Model\Empresa")
     * @ORM\JoinColumn(name="empresa_id", referencedColumnName="id", onDelete="SET NULL")
     */
    private $empresa;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Model\Tax")
     * @ORM\JoinColumn(name="tax_id", referencedColumnName="id", onDelete="SET NULL")
     *
     */
    private $taxes;

    /**
     * @ORM\PrePersist
     */
    public function setSlug()
    {
        $this->slug = md5('sv_'.$this->empresa->getId().$this->reference);
    }

    /**
     * @return string
     */
    public function getSlug(): string
    {
        return $this->slug;
    }


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

    /**
     * Set reference
     *
     * @param string $reference
     *
     * @return Product
     */
    public function setReference($reference)
    {
        $this->reference = strtoupper($reference);

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * 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 string|null
 */
public function getPrice2()
{
    return $this->price2;
}

/**
 * @param string|float|int|null $price2
 *
 * @return Product
 */
public function setPrice2($price2)
{
    $this->price2 = $price2;

    return $this;
}

    public function jsonSerialize()
    {
        return [
            'id' => $this->getId(),
            'reference' => $this->getReference(),
            'price' => $this->getPrice(),
            'description' => $this->getDescription(),
        ];
    }

    public function label()
    {
        return $this->getReference();
    }

    public function __toString()
    {
        return $this->label();
    }

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

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

    /**
     * Add taxes
     *
     * @param App\Entity\Model\Tax $tax
     */
    public function setTaxes(Tax $tax)
    {
        $this->taxes = $tax;
    }


    /**
     * Get taxes
     *
     * @return Tax
     */
    public function getTaxes()
    {
        return $this->taxes;
    }
    
    
    public function getInventarioExistencia()
{
    return $this->inventarioExistencia;
}

public function setInventarioExistencia($inventarioExistencia)
{
    $this->inventarioExistencia = $inventarioExistencia;

    return $this;
}

}
