<?php
namespace App\Entity;
use App\Entity\Traits\TimeStampable;
use App\Repository\PrefectureRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: PrefectureRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Prefecture
{
use TimeStampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 30)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $name;
#[ORM\Column(type: 'decimal', precision: 10, scale: 8, nullable: true)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $latitude;
#[ORM\Column(type: 'decimal', precision: 10, scale: 8, nullable: true)]
#[Assert\NotBlank(message:"Veuillez remplir ce champ")]
private ?string $longitude;
#[ORM\OneToMany(mappedBy: 'prefecture', targetEntity: Municipality::class)]
private Collection $municipalities;
#[ORM\ManyToOne]
private ?User $createdBy = null;
#[ORM\ManyToOne]
private ?User $updatedBy = null;
#[ORM\Column]
private ?bool $isRegion = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'prefectures')]
private ?self $region = null;
#[ORM\OneToMany(mappedBy: 'region', targetEntity: self::class)]
private Collection $prefectures;
public function __construct()
{
$this->municipalities = new ArrayCollection();
$this->createdAt = new DateTimeImmutable();
$this->updatedAt = new DateTimeImmutable();
$this->prefectures = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getLatitude(): ?string
{
return $this->latitude;
}
public function setLatitude(?string $latitude): self
{
$this->latitude = $latitude;
return $this;
}
public function getLongitude(): ?string
{
return $this->longitude;
}
public function setLongitude(?string $longitude): self
{
$this->longitude = $longitude;
return $this;
}
/**
* @return Collection<int, Municipality>
*/
public function getMunicipalities(): Collection
{
return $this->municipalities;
}
public function addMunicipality(Municipality $municipality): self
{
if (!$this->municipalities->contains($municipality)) {
$this->municipalities->add($municipality);
$municipality->setPrefecture($this);
}
return $this;
}
public function removeMunicipality(Municipality $municipality): self
{
if ($this->municipalities->removeElement($municipality)) {
// set the owning side to null (unless already changed)
if ($municipality->getPrefecture() === $this) {
$municipality->setPrefecture(null);
}
}
return $this;
}
public function __toString()
{
return $this->name;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
// public function getUpdatedAt(): ?DateTimeImmutable
// {
// return $this->updatedAt;
// }
public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function isIsRegion(): ?bool
{
return $this->isRegion;
}
public function setIsRegion(bool $isRegion): self
{
$this->isRegion = $isRegion;
return $this;
}
public function getRegion(): ?self
{
return $this->region;
}
public function setRegion(?self $region): self
{
$this->region = $region;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getPrefectures(): Collection
{
return $this->prefectures;
}
public function addPrefecture(self $prefecture): self
{
if (!$this->prefectures->contains($prefecture)) {
$this->prefectures->add($prefecture);
$prefecture->setRegion($this);
}
return $this;
}
public function removePrefecture(self $prefecture): self
{
if ($this->prefectures->removeElement($prefecture)) {
// set the owning side to null (unless already changed)
if ($prefecture->getRegion() === $this) {
$prefecture->setRegion(null);
}
}
return $this;
}
}