<?php
namespace App\Entity;
use App\Repository\ComarcaRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ComarcaRepository::class)]
class Comarca
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Serializer\Groups(groups: ['api'])]
private $id;
#[Assert\NotBlank]
#[ORM\Column(type: 'string', length: 255)]
#[Serializer\Groups(groups: ['api'])]
private ?string $nombre = null;
#[ORM\Column(type: 'boolean')]
private bool $visible = true;
#[ORM\Column(type: 'boolean')]
private bool $borrado = false;
#[ORM\OneToMany(targetEntity: Localidad::class, mappedBy: 'comarca')]
private Collection $localidades;
#[ORM\ManyToOne(targetEntity: Provincia::class, inversedBy: 'comarcas')]
#[ORM\JoinColumn(nullable: false)]
private ?Provincia $provincia = null;
public function __construct()
{
$this->localidades = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNombre(): ?string
{
return $this->nombre;
}
public function setNombre(?string $nombre): self
{
$this->nombre = $nombre;
return $this;
}
public function isVisible(): ?bool
{
return $this->visible;
}
public function setVisible(bool $visible): self
{
$this->visible = $visible;
return $this;
}
public function isBorrado(): ?bool
{
return $this->borrado;
}
public function setBorrado(bool $borrado): self
{
$this->borrado = $borrado;
return $this;
}
/**
* @return Collection<int, Localidad>
*/
public function getLocalidades(): Collection
{
return $this->localidades;
}
public function addLocalidade(Localidad $localidade): self
{
if (!$this->localidades->contains($localidade)) {
$this->localidades[] = $localidade;
$localidade->setComarca($this);
}
return $this;
}
public function removeLocalidade(Localidad $localidade): self
{
// set the owning side to null (unless already changed)
if ($this->localidades->removeElement($localidade) && $localidade->getComarca() === $this) {
$localidade->setComarca(null);
}
return $this;
}
public function getProvincia(): ?Provincia
{
return $this->provincia;
}
public function setProvincia(?Provincia $provincia): self
{
$this->provincia = $provincia;
return $this;
}
}