<?php
namespace App\Entity\Shop\Order;
use App\Entity\BaseEntity;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\Order\CouponRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: CouponRepository::class)]
class Coupon extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $code = null;
#[ORM\Column(nullable: true)]
private ?float $percentage = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $fixedAmount = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $startDate = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $endDate = null;
#[ORM\Column]
private ?int $maxUses = null;
#[ORM\Column]
private ?int $usedCount = null;
#[ORM\ManyToOne(inversedBy: 'coupons')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
#[ORM\OneToMany(mappedBy: 'coupon', targetEntity: Order::class)]
private Collection $orders;
#[ORM\Column(length: 255)]
private ?string $title = null;
public function __construct()
{
parent::__construct();
$this->orders = new ArrayCollection();
$this->setMaxUses(1000000);
$this->setUsedCount(0);
}
public function getId(): ?string
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
public function getPercentage(): ?float
{
return $this->percentage;
}
public function setPercentage(float $percentage): static
{
$this->percentage = $percentage;
return $this;
}
public function getFixedAmount(): ?string
{
return $this->fixedAmount;
}
public function setFixedAmount(?string $fixedAmount): static
{
$this->fixedAmount = $fixedAmount;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(?\DateTimeInterface $startDate): static
{
$this->startDate = $startDate;
return $this;
}
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
public function setEndDate(?\DateTimeInterface $endDate): static
{
$this->endDate = $endDate;
return $this;
}
public function getMaxUses(): ?int
{
return $this->maxUses;
}
public function setMaxUses(int $maxUses): static
{
$this->maxUses = $maxUses;
return $this;
}
public function getUsedCount(): ?int
{
return $this->usedCount;
}
public function setUsedCount(int $usedCount): static
{
$this->usedCount = $usedCount;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
/**
* @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->setCoupon($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCoupon() === $this) {
$order->setCoupon(null);
}
}
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
}