<?php
namespace App\Entity;
use App\Interface\ItemInterface;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* @ORM\Table(name="suppliers__warehouses_items",
* uniqueConstraints={
* @ORM\UniqueConstraint(columns={"item_id", "warehouse_id"}),
* })
* @ORM\Entity(repositoryClass="App\Repository\SupplierWarehouseItemRepository")
*/
class SupplierWarehouseItem implements ItemInterface
{
use IdTrait;
use UpdatedAtTrait;
/**
* @ORM\ManyToOne(targetEntity="SupplierItem")
* @ORM\JoinColumn(name="item_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private SupplierItem $item;
/**
* @ORM\ManyToOne(targetEntity="SupplierWarehouse")
* @ORM\JoinColumn(name="warehouse_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private SupplierWarehouse $warehouse;
/**
* @ORM\Column(name="stock", type="integer", options={"default":0})
*/
private int $stock = 0;
/**
* @ORM\Column(name="show_in_search", type="boolean", options={"default":1})
*/
private bool $showInSearch = true;
/**
* @ORM\Column(name="parsing_task", type="string", nullable=true)
*/
private ?string $parsingTask = null;
/**
* @throws Exception
*/
public function __construct(SupplierItem $item, SupplierWarehouse $warehouse)
{
if($item->getSupplier() !== $warehouse->getSupplier()) throw new Exception('Diff supplier');
$this->item = $item;
$this->warehouse = $warehouse;
}
public function getProduct(): Product
{
return $this->item->getProduct();
}
public function getWarehouse(): SupplierWarehouse
{
return $this->warehouse;
}
public function getStock(): int
{
return $this->stock;
}
public function setStock(int $stock): SupplierWarehouseItem
{
$this->stock = $stock;
return $this;
}
public function getPrice(): int
{
return $this->item->getPrice();
}
public function isShowInSearch(): bool
{
return $this->showInSearch;
}
}