<?php
namespace App\Entity;
use App\Entity\Abstract\Entity;
use App\Repository\TuRepository;
use App\Validator\InputValidator;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Mime\Address as EmailAddress;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: TuRepository::class)]
#[Index(name: "tu_configName_idx", columns: ["configName"])]
class Tu extends Entity
{
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
private ?Uuid $id = null;
#[ORM\Column(length: 100)]
#[Assert\NotBlank(message: 'tu.error.name')]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'tU', targetEntity: PricingModel::class, cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['employeeDiscount' => 'ASC'])]
#[Assert\Valid]
private Collection $pricingModels;
#[ORM\Column(length: 30)]
#[Assert\NotBlank(message: 'tu.error.configName')]
private ?string $configName = null;
#[ORM\OneToMany(mappedBy: 'tu', targetEntity: Enterprise::class)]
private Collection $enterprises;
#[ORM\OneToMany(mappedBy: 'tu', targetEntity: User::class)]
private Collection $users;
#[ORM\Column(length: 80, nullable: true)]
private ?string $senderEmail = null;
#[ORM\Column(length: 80, nullable: true)]
private ?string $senderName = null;
public function __construct()
{
$this->pricingModels = new ArrayCollection();
$this->enterprises = new ArrayCollection();
$this->users = new ArrayCollection();
}
public function getId(): ?Uuid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, PricingModel>
*/
public function getPricingModels(): Collection
{
return $this->pricingModels;
}
public function addPricingModel(PricingModel $pricingModel): static
{
if (!$this->pricingModels->contains($pricingModel)) {
$this->pricingModels->add($pricingModel);
$pricingModel->setTU($this);
}
return $this;
}
public function removePricingModel(PricingModel $pricingModel): static
{
if ($this->pricingModels->removeElement($pricingModel)) {
// set the owning side to null (unless already changed)
if ($pricingModel->getTU() === $this) {
$pricingModel->setTU(null);
}
}
return $this;
}
public function getConfigName(): ?string
{
return $this->configName;
}
public function setConfigName(string $configName): static
{
$this->configName = $configName;
return $this;
}
/**
* @return Collection<int, Enterprise>
*/
public function getEnterprises(): Collection
{
return $this->enterprises;
}
public function addEnterprise(Enterprise $enterprise): static
{
if (!$this->enterprises->contains($enterprise)) {
$this->enterprises->add($enterprise);
$enterprise->setTu($this);
}
return $this;
}
public function removeEnterprise(Enterprise $enterprise): static
{
if ($this->enterprises->removeElement($enterprise)) {
// set the owning side to null (unless already changed)
if ($enterprise->getTu() === $this) {
$enterprise->setTu(null);
}
}
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): static
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setTu($this);
}
return $this;
}
public function removeUser(User $user): static
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getTu() === $this) {
$user->setTu(null);
}
}
return $this;
}
public function getSenderEmail(): ?string
{
return $this->senderEmail;
}
public function setSenderEmail(?string $senderEmail): static
{
$this->senderEmail = $senderEmail;
return $this;
}
public function getSenderName(): ?string
{
return $this->senderName;
}
public function setSenderName(?string $senderName): static
{
$this->senderName = $senderName;
return $this;
}
public function getSenderEmailAddress(): ?EmailAddress
{
$senderEmail = null;
if(!empty($this->senderEmail) && InputValidator::emailAddressValidation($this->senderEmail)){
if(!empty($this->senderName)){
$senderEmail = new EmailAddress($this->senderEmail, $this->senderName);
} else {
$senderEmail = new EmailAddress($this->senderEmail);
}
}
return $senderEmail;
}
}