<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CountryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Symfony\Component\Serializer\Annotation\Ignore;
use function Symfony\Component\String\u;
#[ApiResource(attributes: ['route_prefix' => 'v1'])]
#[Entity(CountryRepository::class)]
#[UniqueConstraint('name', ['name'])]
#[UniqueConstraint('iso_code', ['iso_code'])]
class Country
{
public const DEFAULT_ID = 1000;
#[Id]
#[GeneratedValue]
#[Column(type: 'integer', options: ['unsigned' => true])]
private int $id;
#[Ignore]
#[ManyToOne(targetEntity: Region::class, inversedBy: "countries")]
private ?Region $region = null;
#[Column(type: 'string')]
private string $name;
#[Column(type: 'string', length: 2)]
private string $isoCode;
#[Column(type: 'boolean', options: ['default' => true])]
private bool $smsEnabled;
#[OneToMany('country', CountryPhoneCode::class)]
private Collection $phoneCodes;
#[Column(type: 'float', precision: 10, scale: 2, nullable: false, options: ['unsigned' => true])]
private float $cpmRate = 1;
public function __construct()
{
$this->phoneCodes = new ArrayCollection();
}
public function __toString(): string
{
return u($this->getIsoCode())->upper()->toString();
}
public function getId(): ?int
{
return $this->id;
}
public function getRegion(): ?Region
{
return $this->region;
}
public function setRegion(?Region $region): void
{
$this->region = $region;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setIsoCode(?string $isoCode): self
{
$this->isoCode = $isoCode;
return $this;
}
public function getIsoCode(): ?string
{
return $this->isoCode;
}
public function isSmsEnabled(): bool
{
return $this->smsEnabled;
}
public function setSmsEnabled(bool $smsEnabled): static
{
$this->smsEnabled = $smsEnabled;
return $this;
}
public function getPhoneCodes(): Collection
{
return $this->phoneCodes;
}
public function getCpmRate(): float
{
return $this->cpmRate;
}
public function setCpmRate(float $cpmRate): void
{
$this->cpmRate = $cpmRate;
}
}