<?php
namespace App\Entity;
use App\Entity\Interfaces\MarkingsInterface;
use App\Entity\Traits\MarkingsTrait;
use App\Entity\Traits\MarkingTrait;
use App\Repository\NielsenOrderRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: NielsenOrderRepository::class)]
class NielsenOrder implements MarkingsInterface
{
use MarkingTrait;
use MarkingsTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'nielsenOrders')]
private ?Project $project = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $created = null;
#[ORM\ManyToMany(targetEntity: ClientOrder::class, inversedBy: 'nielsenOrders')]
private Collection $clientOrders;
#[ORM\Column(length: 255, nullable: true)]
private ?string $status = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $reference = null;
#[ORM\OneToMany(mappedBy: 'entity', targetEntity: NielsenOrderMarking::class, orphanRemoval: true)]
#[ORM\OrderBy(['createdAt' => 'ASC'])]
private Collection $markings;
#[ORM\Column(type: Types::JSON)]
private array $shipments = [];
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $updatedAt = null;
public function __construct()
{
$this->clientOrders = new ArrayCollection();
$this->created = new \DateTimeImmutable();
$this->markings = new ArrayCollection();
$this->marking = NielsenOrderMarking::getInitialMarking();
}
public function getId(): ?int
{
return $this->id;
}
public function getProject(): ?Project
{
return $this->project;
}
public function setProject(?Project $project): static
{
$this->project = $project;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): static
{
$this->created = $created;
return $this;
}
/**
* @return Collection<int, ClientOrder>
*/
public function getClientOrders(): Collection
{
return $this->clientOrders;
}
public function addClientOrder(ClientOrder $clientOrder): static
{
if (!$this->clientOrders->contains($clientOrder)) {
$this->clientOrders->add($clientOrder);
}
return $this;
}
public function removeClientOrder(ClientOrder $clientOrder): static
{
$this->clientOrders->removeElement($clientOrder);
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): static
{
$this->status = $status;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): static
{
$this->reference = $reference;
return $this;
}
public function getShipments(): array
{
return $this->shipments;
}
public function setShipments(array $shipments): static
{
$this->shipments = $shipments;
return $this;
}
public function addShipment(
\DateTime $date,
?string $shippingNumber,
string $trackingLink,
): self
{
$this->shipments[] = [
'date' => $date->format("Y-m-d H:i:s"),
'shipping_number' => $shippingNumber ?? null,
'tracking_link' => $trackingLink,
];
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
}