<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use OpenApi\Annotations as OA;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity()
* @ORM\Table(name="`order`")
*/
class Order
{
public const PRECISION = 2;
public const SOURCE_WEB = 'web';
public const SOURCE_INT = 'internal';
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
* @OA\Property(type="string", format="uuid")
*/
#[Groups(['index', 'orderHistory'])]
protected ?Uuid $id = null;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
* @ORM\JoinColumn(nullable=false)
*/
#[Groups(['index'])]
private ?User $user;
/**
* @ORM\ManyToOne(targetEntity=Vin::class, inversedBy="orders", fetch="EAGER")
* @ORM\JoinColumn(nullable=false)
*/
#[Groups(['vin', 'orderHistory'])]
private ?Vin $vin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
#[Groups(['index', 'orderHistory'])]
#[Assert\Email]
private ?string $email = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2)
*/
#[Groups(['index'])]
private ?float $totalSum = null;
/**
* @ORM\Column(type="boolean")
*/
#[Groups(['index', 'orderHistory'])]
private bool $paid = false;
/**
* @ORM\Column(type="boolean")
*/
#[Groups(['index', 'orderHistory'])]
private bool $emailSent = false;
/**
* @ORM\Column(type="datetime")
*/
#[Groups(['orderHistory'])]
private ?\DateTimeInterface $createdAt = null;
/**
* @ORM\OneToMany(targetEntity=Report::class, mappedBy="order", cascade={"persist"})
*/
#[Groups(['report', 'orderHistory'])]
private Collection $reports;
#[Groups(['index'])]
private ?string $merchantId = null;
#[Groups(['index'])]
private ?string $payLink = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
#[Groups(['index'])]
private ?string $reportLink = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $source = null;
/**
* @ORM\ManyToOne(targetEntity=Promocode::class)
*/
private ?Promocode $promocode = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $emailPreReportSend = false;
public function __construct()
{
$this->reports = new ArrayCollection();
}
public function __toString(): string
{
return $this->id . '_' . $this->getVin()?->getVin();
}
public function getId(): ?Uuid
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getVin(): ?Vin
{
return $this->vin;
}
public function setVin(?Vin $vin): self
{
$this->vin = $vin;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getTotalSum(): ?float
{
return $this->totalSum;
}
public function setTotalSum(float $totalSum): self
{
$this->totalSum = \round($totalSum, self::PRECISION);
return $this;
}
public function getPaid(): bool
{
return $this->paid;
}
public function setPaid(bool $paid): self
{
$this->paid = $paid;
return $this;
}
public function getEmailSent(): bool
{
return $this->emailSent;
}
public function setEmailSent(bool $emailSent = true): Order
{
$this->emailSent = $emailSent;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getReports(): Collection
{
return $this->reports;
}
public function addReport(Report $report): self
{
if (!$this->reports->contains($report)) {
$this->reports[] = $report;
$report->setOrder($this);
}
return $this;
}
public function removeReport(Report $report): self
{
if ($this->reports->removeElement($report)) {
if ($report->getOrder() === $this) {
$report->setOrder(null);
}
}
return $this;
}
public function getMerchantId(): ?string
{
return $this->merchantId;
}
public function setMerchantId(?string $merchantId): self
{
$this->merchantId = $merchantId;
return $this;
}
public function getPayLink(): ?string
{
return $this->payLink;
}
public function setPayLink(?string $payLink): self
{
$this->payLink = $payLink;
return $this;
}
public function toLog(): array
{
return [
'orderId' => (string) $this->id,
'vin' => (string) $this->vin,
'email' => $this->email,
'source' => (string) $this->getSource(),
];
}
public function getPromocode(): ?Promocode
{
return $this->promocode;
}
public function setPromocode(?Promocode $promocode): self
{
$this->promocode = $promocode;
return $this;
}
public function getReportLink(): ?string
{
return $this->reportLink;
}
public function setReportLink(?string $reportLink): self
{
$this->reportLink = $reportLink;
return $this;
}
/**
* @return string|null
*/
public function getSource(): ?string
{
return $this->source;
}
public function setSource(?string $source): self
{
$this->source = $source;
return $this;
}
public function getEmailPreReportSend(): ?bool
{
return $this->emailPreReportSend;
}
public function setEmailPreReportSend(?bool $emailPreReportSend = true): self
{
$this->emailPreReportSend = $emailPreReportSend;
return $this;
}
}