<?php
namespace App\Entity\Channel;
use App\Entity\Common\Contact;
use App\Enum\Serialization\CompanyContactSerializationGroups;
use App\Enum\Serialization\ReverseSyncSerializationGroups;
use App\Repository\Channel\CompanyContactRepository;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Channel\Entity\CompanyContact\CompanyContactInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\CompanyContact\CompanyContactMethodTrait;
use Nellapp\Bundle\SDKBundle\ReverseSync\Entity\ReverseSyncableInterface;
use Nellapp\Bundle\SDKBundle\ReverseSync\EntityKeys;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: CompanyContactRepository::class),
ORM\Table(name: 'channel_company_contacts')
]
class CompanyContact implements CompanyContactInterface, ReverseSyncableInterface
{
use CompanyContactMethodTrait;
#[
ORM\Id,
ORM\GeneratedValue(strategy: 'NONE'),
ORM\Column(type: 'string', length: 36)
]
#[Serial\Groups([
CompanyContactSerializationGroups::COLLECTION,
CompanyContactSerializationGroups::DETAIL,
ReverseSyncSerializationGroups::REVERSE_SYNC,
])]
private ?string $id = null;
#[ORM\Column(type: 'json')]
#[Serial\Groups([
ReverseSyncSerializationGroups::REVERSE_SYNC,
])]
private array $behaviors = [];
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'companyContacts')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups([ReverseSyncSerializationGroups::REVERSE_SYNC])]
private Company $company;
#[ORM\ManyToOne(targetEntity: ChannelContact::class, inversedBy: 'companyContacts')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups([ReverseSyncSerializationGroups::REVERSE_SYNC])]
#[Assert\Valid()]
private ChannelContact $channelContact;
public function __construct()
{
$this->initCompanyContactMethod();
}
public static function getReverseSyncKey(): string
{
return EntityKeys::COMPANY_CONTACT;
}
public function __toString()
{
return $this->channelContact->getContact()->getFullName() ?? '';
}
}