<?php
namespace App\Entity;
use App\Model\Country;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(
* name="end_customer",
* options={"collate"="utf8_swedish_ci"}
* )
* @ORM\HasLifecycleCallbacks
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(
* name="entity",
* type="string",
* length=50
* )
* @ORM\DiscriminatorMap({
* "company"="CompanyEndCustomer",
* "document"="DocumentEndCustomer"
* })
*/
abstract class EndCustomer implements EntityInterface
{
/**
* @ORM\Id
* @ORM\Column(
* type="integer"
* )
* @ORM\GeneratedValue(
* strategy="AUTO"
* )
*
* @var int|null
*/
protected ?int $id = null;
/**
* @ORM\Column(
* type="string",
* length=5,
* nullable=true
* )
*
* @var string|null
*/
protected ?string $country = null;
/**
* @ORM\Column(
* type="string",
* length=1000
* )
* @Assert\NotBlank
*
* @var string
*/
protected string $name;
/**
* @param string $name
*/
public function __construct(string $name)
{
$this->name = $name;
}
public function __clone()
{
$this->id = null;
}
/**
* @return string
*/
public function __toString(): string
{
$str = $this->name;
if (null !== $country = $this->getCountryName()) {
$str .= ', ' . $country;
}
return $str;
}
/**
* @return string|null
*/
public function getCountry(): ?string
{
return $this->country;
}
/**
* @return string|null
*/
public function getCountryName(): ?string
{
if (null !== $this->country) {
$country = new Country($this->country);
return $country->getName();
}
return null;
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return array
*/
public function serialize(): array
{
return [
'id' => $this->getId(),
'name' => $this->getName(),
'country' => $this->getCountry(),
];
}
/**
* @param string|null $country
*/
public function setCountry(?string $country): void
{
$this->country = $country;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
}