<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\PwCityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
#[ORM\Entity(repositoryClass: PwCityRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['PwCity:read']],
denormalizationContext: ['groups' => ['PwCity:write']],
cacheHeaders: [
'max_age' => 3600,
'shared_max_age' => 7200,
'vary' => ['Authorization', 'Accept-Language']
],
)]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial', 'otg.id' => 'exact', 'codeOtg' => 'exact'])]
class PwCity
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\Column]
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwCity:read', 'PwAddressQ:read'])]
private ?int $id = null;
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwCity:read', 'PwAddressQ:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['PwAccident:read', 'PwAccident:write', 'PwCity:read', 'PwAddressQ:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $codeOtg = null;
#[ORM\OneToMany(mappedBy: 'city', targetEntity: PwStreet::class)]
private Collection $pwStreets;
#[ORM\OneToMany(mappedBy: 'city', targetEntity: PwAccident::class)]
private Collection $pwAccidents;
#[Groups(['PwCity:read'])]
#[ORM\ManyToOne(inversedBy: 'pwCities')]
private ?PwOtg $otg = null;
#[ORM\OneToMany(mappedBy: 'city', targetEntity: PwAccount::class)]
private Collection $accounts;
#[ORM\OneToMany(mappedBy: 'city', targetEntity: PwAddressQueue::class)]
private Collection $pwAddressQueues;
public function __construct()
{
$this->pwStreets = new ArrayCollection();
$this->pwAccidents = new ArrayCollection();
$this->accounts = new ArrayCollection();
$this->pwAddressQueues = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getCodeOtg(): ?string
{
return $this->codeOtg;
}
public function setCodeOtg(?string $codeOtg): static
{
$this->codeOtg = $codeOtg;
return $this;
}
/**
* @return Collection<int, PwStreet>
*/
public function getPwStreets(): Collection
{
return $this->pwStreets;
}
public function addPwStreet(PwStreet $pwStreet): static
{
if (!$this->pwStreets->contains($pwStreet)) {
$this->pwStreets->add($pwStreet);
$pwStreet->setCity($this);
}
return $this;
}
public function removePwStreet(PwStreet $pwStreet): static
{
if ($this->pwStreets->removeElement($pwStreet)) {
// set the owning side to null (unless already changed)
if ($pwStreet->getCity() === $this) {
$pwStreet->setCity(null);
}
}
return $this;
}
/**
* @return Collection<int, PwAccident>
*/
public function getPwAccidents(): Collection
{
return $this->pwAccidents;
}
public function addPwAccident(PwAccident $pwAccident): static
{
if (!$this->pwAccidents->contains($pwAccident)) {
$this->pwAccidents->add($pwAccident);
$pwAccident->setCity($this);
}
return $this;
}
public function removePwAccident(PwAccident $pwAccident): static
{
if ($this->pwAccidents->removeElement($pwAccident)) {
// set the owning side to null (unless already changed)
if ($pwAccident->getCity() === $this) {
$pwAccident->setCity(null);
}
}
return $this;
}
public function getOtg(): ?PwOtg
{
return $this->otg;
}
public function setOtg(?PwOtg $otg): static
{
$this->otg = $otg;
return $this;
}
/**
* @return Collection<int, PwAccount>
*/
public function getAccounts(): Collection
{
return $this->accounts;
}
public function addAccount(PwAccount $account): static
{
if (!$this->accounts->contains($account)) {
$this->accounts->add($account);
$account->setCity($this);
}
return $this;
}
public function removeAccount(PwAccount $account): static
{
if ($this->accounts->removeElement($account)) {
// set the owning side to null (unless already changed)
if ($account->getCity() === $this) {
$account->setCity(null);
}
}
return $this;
}
/**
* @return Collection<int, PwAddressQueue>
*/
public function getPwAddressQueues(): Collection
{
return $this->pwAddressQueues;
}
public function addPwAddressQueue(PwAddressQueue $pwAddressQueue): static
{
if (!$this->pwAddressQueues->contains($pwAddressQueue)) {
$this->pwAddressQueues->add($pwAddressQueue);
$pwAddressQueue->setCity($this);
}
return $this;
}
public function removePwAddressQueue(PwAddressQueue $pwAddressQueue): static
{
if ($this->pwAddressQueues->removeElement($pwAddressQueue)) {
// set the owning side to null (unless already changed)
if ($pwAddressQueue->getCity() === $this) {
$pwAddressQueue->setCity(null);
}
}
return $this;
}
}