<?php
namespace App\Entity;
use App\Repository\CountryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CountryRepository::class)]
#[ORM\Table(name: 'country')]
class Country
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 100)]
private ?string $name = null;
#[ORM\Column(name: 'iso_code', length: 2, unique: true)]
private ?string $isoCode = null;
#[ORM\Column(name: 'phone_code', length: 8, nullable: true)]
private ?string $phoneCode = null;
/** @var Collection<int, Region> */
#[ORM\OneToMany(mappedBy: 'country', targetEntity: Region::class, cascade: ['persist'])]
private Collection $regions;
public function __construct()
{
$this->regions = 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 getIsoCode(): ?string { return $this->isoCode; }
public function setIsoCode(string $isoCode): self { $this->isoCode = strtoupper($isoCode); return $this; }
public function getPhoneCode(): ?string { return $this->phoneCode; }
public function setPhoneCode(?string $phoneCode): self { $this->phoneCode = $phoneCode; return $this; }
/** @return Collection<int, Region> */
public function getRegions(): Collection { return $this->regions; }
public function addRegion(Region $region): self
{
if (!$this->regions->contains($region)) {
$this->regions->add($region);
$region->setCountry($this);
}
return $this;
}
public function removeRegion(Region $region): self
{
if ($this->regions->removeElement($region)) {
if ($region->getCountry() === $this) {
$region->setCountry(null);
}
}
return $this;
}
public function __toString(): string { return $this->name ?? ''; }
}