<?php
namespace App\Entity\ContractPrice;
use App\Entity\Extension\HistoricalInterface;
use App\Entity\Extension\HistoricalTrait;
use App\Entity\Extension\TimestampableTrait;
use App\Entity\Extension\UnlistableTrait;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use App\Entity\Gauge\Supplier;
use App\Entity\File;
use App\Entity\Gauge\Gauge;
use App\Repository\ContractPrice\ContractRepository;
use Ramsey\Uuid\UuidInterface;
/**
* @ORM\Entity(repositoryClass=ContractRepository::class)
* @ORM\Table(name="contract")
*/
class Contract implements HistoricalInterface
{
use TimestampableTrait;
use UnlistableTrait;
use HistoricalTrait;
/**
* @var ?UuidInterface
*
* @ORM\Id()
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\Column(type="uuid", unique=true)
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
private ?UuidInterface $id;
/**
* @ORM\ManyToOne(targetEntity=Supplier::class)
* @ORM\JoinColumn(name="supplier_id", referencedColumnName="id", nullable=false)
*/
private Supplier $supplier;
/**
* @ORM\ManyToOne(targetEntity=File::class)
* @ORM\JoinColumn(name="file_id", referencedColumnName="id", nullable=true)
*/
private ?File $file = null;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private bool $manual = false;
/**
* E.g. "electricity", "gas" ...
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $medium = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $deliveryMethod = null;
/**
* @ORM\Column(type="date")
*/
private \DateTimeInterface $validTo;
/**
* @ORM\OneToMany(targetEntity=ContractItem::class, mappedBy="contract", cascade={"persist","remove"})
* @var Collection|ContractItem[]
*/
private $items;
/**
* @ORM\ManyToMany(targetEntity=Gauge::class)
* @ORM\JoinTable(name="gauges_contract",
* joinColumns={@ORM\JoinColumn(name="contract_price_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="gauge_id", referencedColumnName="id", onDelete="CASCADE")}
* )
* @var Collection|Gauge[]
*/
private $gauges;
public function __construct()
{
$this->items = new ArrayCollection();
$this->gauges = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function hasId(): bool
{
return isset($this->id);
}
public function getSupplier(): Supplier
{
return $this->supplier;
}
public function setSupplier(Supplier $supplier): self
{
$this->supplier = $supplier;
return $this;
}
public function getFile(): ?File
{
return $this->file;
}
public function setFile(?File $file): self
{
$this->file = $file;
return $this;
}
public function getManual(): bool
{
return $this->manual;
}
public function setManual(bool $manual): self
{
$this->manual = $manual;
return $this;
}
public function getMedium(): ?int
{
return $this->medium;
}
public function setMedium(?string $medium): self
{
$this->medium = $medium;
return $this;
}
public function getDeliveryMethod(): ?string
{
return $this->deliveryMethod;
}
public function setDeliveryMethod(?string $deliveryMethod): self
{
$this->deliveryMethod = $deliveryMethod;
return $this;
}
public function getValidTo(): \DateTimeInterface
{
return $this->validTo;
}
public function setValidTo(\DateTimeInterface $validTo): self
{
$this->validTo = $validTo;
return $this;
}
/** @return Collection<int, ContractItem> */
public function getItems(): Collection
{
return $this->items;
}
public function addItem(ContractItem $item): self
{
if (!$this->items->contains($item)) {
$this->items[] = $item;
$item->setContract($this);
}
return $this;
}
public function removeItem(ContractItem $item): self
{
$this->items->removeElement($item);
return $this;
}
/** @return Collection<int, Gauge> */
public function getGauges(): Collection
{
return $this->gauges;
}
public function addGauge(Gauge $gauge): self
{
if (!$this->gauges->contains($gauge)) {
$this->gauges[] = $gauge;
}
return $this;
}
public function removeGauge(Gauge $gauge): self
{
$this->gauges->removeElement($gauge);
return $this;
}
}