<?php
namespace App\Entity\Channel;
use App\Entity\Account\User;
use App\Entity\Common\Contact;
use App\Repository\Channel\ChannelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelMethodTrait;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelPropertyTrait;
use Symfony\Component\Serializer\Annotation as Serial;
#[ORM\Entity(repositoryClass: ChannelRepository::class)]
#[ORM\Table(name: 'channel_channels')]
class Channel implements ChannelInterface
{
use ChannelMethodTrait;
use ChannelPropertyTrait;
#[ORM\Id, ORM\Column(type: 'string', length: 36)]
#[Serial\Groups(['GlobalJSVariable'])]
private ?string $id = null;
#[ORM\Column(type: 'string')]
#[Serial\Groups(['GlobalJSVariable'])]
private ?string $name = null;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $imagePath = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $paymentAlert = false;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $owner = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $enabledIndexing = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $enabledChatBot = false;
#[ORM\OneToOne(inversedBy: 'channel', targetEntity: ChannelConfiguration::class, fetch: 'LAZY', orphanRemoval: true)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?ChannelConfiguration $configuration = null;
#[ORM\ManyToMany(targetEntity: Contact::class, mappedBy: 'channels')]
private Collection $contacts;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: Drive::class)]
private Collection $drives;
public function __construct()
{
$this->contacts = new ArrayCollection();
$this->drives = new ArrayCollection();
}
public function getConfiguration(): ?ChannelConfiguration
{
return $this->configuration;
}
public function setConfiguration(?ChannelConfiguration $configuration): static
{
$this->configuration = $configuration;
return $this;
}
public function getContacts(): Collection
{
return $this->contacts ?? $this->contacts = new ArrayCollection();
}
public function setContacts(Collection $contacts): static
{
$this->contacts = $contacts;
return $this;
}
public function addContact(Contact $contact): static
{
$contacts = $this->getContacts();
if (!$contacts->contains($contact)) {
$contacts->add($contact);
$contact->addChannel($this);
}
return $this;
}
public function removeContact(Contact $contact): static
{
$contacts = $this->getContacts();
if ($contacts->contains($contact)) {
$contacts->removeElement($contact);
$contact->removeChannel($this);
}
return $this;
}
/**
* @return Collection<int, Drive>
*/
public function getDrives(): Collection
{
return $this->drives;
}
public function addDrive(Drive $drive): static
{
if (!$this->drives->contains($drive)) {
$this->drives->add($drive);
$drive->setChannel($this);
}
return $this;
}
public function removeDrive(Drive $drive): static
{
if ($this->drives->removeElement($drive)) {
// set the owning side to null (unless already changed)
if ($drive->getChannel() === $this) {
$drive->setChannel(null);
}
}
return $this;
}
}