<?php
namespace App\Entity\Channel;
use App\Entity\Common\Contact;
use App\Entity\Sync\SyncableInterface;
use App\Repository\Channel\ChannelContactRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OneToMany;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Archivable\Entity\ArchivableTrait;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelContact\ChannelContactInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelContact\ChannelContactMethodTrait;
use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation as Serial;
#[
ORM\Entity(repositoryClass: ChannelContactRepository::class),
ORM\Table(name: 'channel_contacts'),
ORM\UniqueConstraint(fields: ['channel', 'contact']),
UniqueEntity(fields: ['channel', 'contact'], message: 'channel_contact.UniqueEntity')
]
class ChannelContact implements SyncableInterface, ChannelContactInterface
{
use ArchivableTrait;
use ChannelContactMethodTrait;
#[
ORM\Id,
ORM\GeneratedValue(strategy: 'NONE'),
ORM\Column(type: 'string', length: 36)
]
#[Serial\Groups(['Sync', 'Manager'])]
private ?string $id = null;
#[ORM\ManyToOne(targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups(['Sync'])]
private ?Channel $channel = null;
#[ORM\ManyToOne(targetEntity: Contact::class, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups(['Sync'])]
#[Serial\Groups(['Manager'])]
private ?Contact $contact = null;
#[OneToMany(mappedBy: 'channelContact', targetEntity: CompanyContact::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $companyContacts;
public function __construct()
{
$this->initChannelContactMethod();
$this->companyContacts = new ArrayCollection();
}
public static function getSyncKey(): string
{
return EntityKeys::CHANNEL_CONTACT;
}
public function getSyncDisplayLabel(): string
{
return sprintf('Contact : %s pour la chaƮne : %s ', $this->contact, $this->channel);
}
#[Serial\Groups(['Sync'])]
public function getArchivedAt(): ?\DateTimeImmutable
{
return $this->archivedAt;
}
}