<?php
namespace App\Entity;
use App\Repository\CustomerRepository;
use App\Trait\Identity;
use App\Trait\Person;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: "dtype", type: "string")]
#[ORM\DiscriminatorMap(['moral' => CustomerMoral::class, 'physical' => CustomerPhysical::class])]
#[ORM\Entity(repositoryClass: CustomerRepository::class)]
#[UniqueEntity(['email'])]
class Customer
{
use TimestampableEntity;
use Person;
use Identity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['customer:read'])]
private ?int $id;
#[ORM\Column(length: 255, nullable: true)]
private ?string $auxiliaryCode = null; // for accountancy (optional)
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $note = null;
#[ORM\Column(length: 3, nullable: true)]
#[Groups(['customer:read'])]
private ?string $currency;
#[ORM\ManyToOne]
private ?Market $market = null;
#[ORM\ManyToOne]
private ?City $city = null;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: CustomerInfoType::class, orphanRemoval: true)]
private Collection $customerInfoTypes;
#[ORM\ManyToOne(targetEntity: self::class)]
private ?self $parent = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
private ?FileData $logo = null;
#[ORM\Column(nullable: true)]
private ?bool $isDefault = null;
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
private ?bool $active = null;
#[ORM\Column(nullable: true)]
private ?bool $showAllHotelXml = null;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: CustomerAirlineXmlApi::class)]
private Collection $customerAirlineXmlApis;
public function __construct()
{
$this->customerInfoTypes = new ArrayCollection();
$this->customerAirlineXmlApis = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getMarket(): ?Market
{
return $this->market;
}
public function setMarket(?Market $market): self
{
$this->market = $market;
return $this;
}
public function getAuxiliaryCode(): ?string
{
return $this->auxiliaryCode;
}
public function setAuxiliaryCode(?string $auxiliary_code): self
{
$this->auxiliaryCode = $auxiliary_code;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getCity(): ?City
{
return $this->city;
}
public function setCity(?City $city): self
{
$this->city = $city;
return $this;
}
/**
* @return Collection<int, CustomerInfoType>
*/
public function getCustomerInfoTypes(): Collection
{
return $this->customerInfoTypes;
}
public function addCustomerInfoType(CustomerInfoType $customerInfoType): self
{
if (!$this->customerInfoTypes->contains($customerInfoType)) {
$this->customerInfoTypes->add($customerInfoType);
$customerInfoType->setCustomer($this);
}
return $this;
}
public function removeCustomerInfoType(CustomerInfoType $customerInfoType): self
{
if ($this->customerInfoTypes->removeElement($customerInfoType)) {
// set the owning side to null (unless already changed)
if ($customerInfoType->getCustomer() === $this) {
$customerInfoType->setCustomer(null);
}
}
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
public function getLogo(): ?FileData
{
return $this->logo;
}
public function setLogo(?FileData $logo): self
{
$this->logo = $logo;
return $this;
}
public function isIsDefault(): ?bool
{
return $this->isDefault;
}
public function setIsDefault(?bool $isDefault): self
{
$this->isDefault = $isDefault;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function __toString(): string
{
return $this->name;
}
public function getApiKey(): ?string
{
return hash('md5', $this->getId());
}
public function isShowAllHotelXml(): ?bool
{
return $this->showAllHotelXml;
}
public function setShowAllHotelXml(bool $showAllHotelXml): static
{
$this->showAllHotelXml = $showAllHotelXml;
return $this;
}
public function getResellerMargin(): ?float
{
return 0;
}
public function getClass() : string {
return "Customer";
}
/**
* @return Collection<int, CustomerAirlineXmlApi>
*/
public function getCustomerAirlineXmlApis(): Collection
{
return $this->customerAirlineXmlApis;
}
public function addCustomerAirlineXmlApi(CustomerAirlineXmlApi $customerAirlineXmlApi): static
{
if (!$this->customerAirlineXmlApis->contains($customerAirlineXmlApi)) {
$this->customerAirlineXmlApis->add($customerAirlineXmlApi);
$customerAirlineXmlApi->setCustomer($this);
}
return $this;
}
public function removeCustomerAirlineXmlApi(CustomerAirlineXmlApi $customerAirlineXmlApi): static
{
if ($this->customerAirlineXmlApis->removeElement($customerAirlineXmlApi)) {
// set the owning side to null (unless already changed)
if ($customerAirlineXmlApi->getCustomer() === $this) {
$customerAirlineXmlApi->setCustomer(null);
}
}
return $this;
}
}