<?php
namespace App\Entity;
use App\Constants\ActiveConstants;
use App\Constants\OperatorTypeConstants;
use App\Repository\OperatorRepository;
use App\Traits\ActivityTrait;
use App\Traits\TimeTrackTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: OperatorRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[UniqueEntity(fields: ['type'])]
class Operator
{
use TimeTrackTrait;
use ActivityTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 191, nullable: true)]
private ?string $name = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $topUpLink = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $priceText = null;
#[ORM\ManyToMany(targetEntity: "App\Entity\Company", inversedBy: 'operators', cascade: ['persist'], orphanRemoval: false)]
#[ORM\JoinTable(name: 'operators_companies')]
#[ORM\JoinColumn(name: 'operator_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\InverseJoinColumn(name: 'company_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
private $companies;
#[ORM\OneToMany(mappedBy: 'operator', targetEntity: PhoneNumber::class, orphanRemoval: true)]
private Collection $phoneNumbers;
#[ORM\OneToMany(mappedBy: 'operator', targetEntity: Tariff::class, orphanRemoval: true)]
private Collection $tariffs;
/**
* @var string
*/
#[ORM\Column(name: 'slug', type: 'string', length: 191, unique: true, nullable: true)]
#[Gedmo\Slug(fields: ['name'], updatable: false)]
private $slug;
#[ORM\Column(type: 'integer', length: 11)]
private $type;
#[ORM\Column(type: 'integer', length: 11, nullable: true)]
private ?int $minNumberQty;
#[ORM\Column(name: 'position', type: 'integer', nullable: true, options: ['unsigned' => true])]
#[Gedmo\SortablePosition]
private ?int $position = 1;
#[ORM\Column(type: 'integer', options: ['default' => 5])]
private int $purchaseLimit = 5;
#[ORM\OneToMany(mappedBy: 'operator', targetEntity: FaqQuestion::class, orphanRemoval: false)]
private Collection $faqQuestions;
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private $isServerActive = true;
#[ORM\Column(type: 'text', nullable: true)]
private $inactiveText;
private bool $connectionError = false;
public function isServerActive(): ?bool
{
return $this->isServerActive;
}
public function setIsServerActive(bool $isServerActive): self
{
$this->isServerActive = $isServerActive;
return $this;
}
public function getInactiveText(): ?string
{
return $this->inactiveText;
}
public function setInactiveText(?string $inactiveText): self
{
$this->inactiveText = $inactiveText;
return $this;
}
public function __construct()
{
$this->companies = new ArrayCollection();
$this->phoneNumbers = new ArrayCollection();
$this->tariffs = new ArrayCollection();
$this->faqQuestions = new ArrayCollection();
}
public function setConnectionError(bool $connectionError): static
{
$this->connectionError = $connectionError;
return $this;
}
public function getConnectionError(): bool
{
return $this->connectionError;
}
public function __toString()
{
return $this->getName();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
/**
* Set createdAt.
*
* @param \DateTime|null $createdAt
*
* @return Operator
*/
public function setCreatedAt($createdAt = null)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt.
*
* @return \DateTime|null
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt.
*
* @param \DateTime|null $updatedAt
*
* @return Operator
*/
public function setUpdatedAt($updatedAt = null)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt.
*
* @return \DateTime|null
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set active.
*
* @param int $active
*
* @return Operator
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active.
*
* @return int
*/
public function getActive()
{
return $this->active;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): static
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
}
return $this;
}
public function removeCompany(Company $company): static
{
$this->companies->removeElement($company);
return $this;
}
/**
* @return Collection<int, PhoneNumber>
*/
public function getPhoneNumbers(): Collection
{
return $this->phoneNumbers;
}
public function addPhoneNumber(PhoneNumber $phoneNumber): static
{
if (!$this->phoneNumbers->contains($phoneNumber)) {
$this->phoneNumbers->add($phoneNumber);
$phoneNumber->setOperator($this);
}
return $this;
}
public function removePhoneNumber(PhoneNumber $phoneNumber): static
{
if ($this->phoneNumbers->removeElement($phoneNumber)) {
// set the owning side to null (unless already changed)
if ($phoneNumber->getOperator() === $this) {
$phoneNumber->setOperator(null);
}
}
return $this;
}
/**
* @return Collection<int, Tariff>
*/
public function getTariffs(): Collection
{
return $this->tariffs;
}
public function addTariff(Tariff $tariff): static
{
if (!$this->tariffs->contains($tariff)) {
$this->tariffs->add($tariff);
$tariff->setOperator($this);
}
return $this;
}
public function removeTariff(Tariff $tariff): static
{
if ($this->tariffs->removeElement($tariff)) {
// set the owning side to null (unless already changed)
if ($tariff->getOperator() === $this) {
$tariff->setOperator(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): static
{
$this->type = $type;
return $this;
}
public function getTypeLabel(): string
{
$types = OperatorTypeConstants::getTranslatedValues();
return $types[$this->type] ?? (string)$this->type;
}
public function getActiveLabel(): string
{
return (isset($this->active) && $this->active) ? ActiveConstants::LABEL_YES : ActiveConstants::LABEL_NO;
}
public function getIsServerActiveLabel(): string
{
return $this->isServerActive ? ActiveConstants::LABEL_YES : ActiveConstants::LABEL_NO;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getTopUpLink(): ?string
{
return $this->topUpLink;
}
public function setTopUpLink(?string $topUpLink): static
{
$this->topUpLink = $topUpLink;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): static
{
$this->position = $position;
return $this;
}
public function getPriceText(): ?string
{
return $this->priceText;
}
public function setPriceText(?string $priceText): static
{
$this->priceText = $priceText;
return $this;
}
public function getMinNumberQty(): ?int
{
return $this->minNumberQty;
}
public function setMinNumberQty(?int $minNumberQty): static
{
$this->minNumberQty = $minNumberQty;
return $this;
}
/**
* @return Collection<int, FaqQuestion>
*/
public function getFaqQuestions(): Collection
{
return $this->faqQuestions;
}
public function addFaqQuestion(FaqQuestion $faqQuestion): static
{
if (!$this->faqQuestions->contains($faqQuestion)) {
$this->faqQuestions->add($faqQuestion);
$faqQuestion->setOperator($this);
}
return $this;
}
public function removeFaqQuestion(FaqQuestion $faqQuestion): static
{
if ($this->faqQuestions->removeElement($faqQuestion)) {
// set the owning side to null (unless already changed)
if ($faqQuestion->getOperator() === $this) {
$faqQuestion->setOperator(null);
}
}
return $this;
}
public function getPurchaseLimit(): int
{
return $this->purchaseLimit;
}
public function setPurchaseLimit(int $purchaseLimit): self
{
$this->purchaseLimit = $purchaseLimit;
return $this;
}
}