<?php
namespace App\Entity;
use App\Repository\GiftVoucherRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: GiftVoucherRepository::class)]
#[ORM\HasLifecycleCallbacks]
class GiftVoucher extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, unique: true)]
private ?string $code = null;
#[ORM\Column(type: Types::DECIMAL, precision: 19, scale: 4)]
private ?string $initialAmount = null;
#[ORM\Column(type: Types::DECIMAL, precision: 19, scale: 4)]
private ?string $balance = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $expiryDate = null;
#[ORM\Column(length: 50)]
private ?string $status = 'ACTIVE'; // ACTIVE, DEPLETED, EXPIRED, CANCELLED
#[ORM\ManyToOne(inversedBy: 'giftVouchers')]
private ?Customer $customer = null;
#[ORM\OneToMany(mappedBy: 'voucher', targetEntity: GiftVoucherUsage::class)]
private Collection $usages;
public function __construct()
{
$this->usages = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
public function getInitialAmount(): ?string
{
return $this->initialAmount;
}
public function setInitialAmount(string $initialAmount): static
{
$this->initialAmount = $initialAmount;
return $this;
}
public function getBalance(): ?string
{
return $this->balance;
}
public function setBalance(string $balance): static
{
$this->balance = $balance;
return $this;
}
public function getExpiryDate(): ?\DateTimeInterface
{
return $this->expiryDate;
}
public function setExpiryDate(\DateTimeInterface $expiryDate): static
{
$this->expiryDate = $expiryDate;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer): static
{
$this->customer = $customer;
return $this;
}
/**
* @return Collection<int, GiftVoucherUsage>
*/
public function getUsages(): Collection
{
return $this->usages;
}
public function addUsage(GiftVoucherUsage $usage): static
{
if (!$this->usages->contains($usage)) {
$this->usages->add($usage);
$usage->setVoucher($this);
}
return $this;
}
public function removeUsage(GiftVoucherUsage $usage): static
{
if ($this->usages->removeElement($usage)) {
// set the owning side to null (unless already changed)
if ($usage->getVoucher() === $this) {
$usage->setVoucher(null);
}
}
return $this;
}
}