<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
#[ORM\Entity]
#[ORM\Table(name: 'voucher_code')]
class VoucherCode
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Voucher::class, inversedBy: "codes")]
#[ORM\JoinColumn(name: "voucher_id", referencedColumnName: "id", onDelete: "CASCADE", nullable: false)]
private ?Voucher $voucher = null;
#[ORM\Column(length: 50, unique: true, options: ['collation' => 'utf8mb4_bin'])]
private string $code;
#[ORM\OneToMany(mappedBy: 'voucherCode', targetEntity: Order::class)]
private Collection $orders;
public function __construct()
{
$this->orders = new ArrayCollection();
}
public function __toString(): string
{
return $this->code;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setVoucherCode($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
if ($order->getVoucherCode() === $this) {
$order->setVoucherCode(null);
}
}
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getVoucher(): ?Voucher
{
return $this->voucher;
}
public function setVoucher(?Voucher $voucher): self
{
$this->voucher = $voucher;
return $this;
}
public function getCode(): string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
}