<?php
namespace App\Entity\PointsCatalog;
use App\Annotation\SiteAware;
use App\Entity\AbstractBase;
use App\Entity\Interfaces\SiteInterface;
use App\Entity\Traits\SiteTrait;
use App\Repository\PointsCatalog\CatalogGiftHasProviderRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Money\Currency;
use Money\Money;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="vulco_points_catalog_gift_has_provider", indexes={@ORM\Index(name="catalog_gift_has_provider_site_idx", columns={"site"})})
* @ORM\Entity(repositoryClass=CatalogGiftHasProviderRepository::class)
* @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
* @SiteAware(siteFieldName="site")
*/
class CatalogGiftHasProvider extends AbstractBase implements SiteInterface
{
use SiteTrait;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PointsCatalog\CatalogGift", inversedBy="providers")
*/
private CatalogGift $gift;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PointsCatalog\CatalogGiftProvider", inversedBy="gifts")
* @Assert\NotBlank()
*/
private CatalogGiftProvider $provider;
/**
* @ORM\Column(type="integer")
* @Assert\NotNull()
*/
private int $priceAmount;
/**
* @ORM\Column(type="string", length=64)
*/
private string $priceCurrency;
public function getGift(): CatalogGift
{
return $this->gift;
}
public function setGift(CatalogGift $gift): self
{
$this->gift = $gift;
return $this;
}
public function getProvider(): CatalogGiftProvider
{
return $this->provider;
}
public function setProvider(CatalogGiftProvider $provider): self
{
$this->provider = $provider;
return $this;
}
public function getPrice(): ?Money
{
if (!$this->priceCurrency) {
return null;
}
if (!$this->priceAmount) {
return new Money(0, new Currency($this->priceCurrency));
}
return new Money($this->priceAmount, new Currency($this->priceCurrency));
}
public function setPrice(Money $price): self
{
$this->priceAmount = $price->getAmount();
$this->priceCurrency = $price->getCurrency()->getCode();
return $this;
}
public function __toString(): string
{
return 'ID#'.$this->id.' ';
}
}