<?php
namespace App\Entity\Channel;
use App\Entity\Sync\SyncableInterface;
use App\Repository\Channel\ChannelWhiteLabelRepository;
use App\Validator\Constraints\DomainResolutionConstraint;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelWhiteLabel\ChannelWhiteLabelInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelWhiteLabel\ChannelWhiteLabelMethodTrait;
use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ChannelWhiteLabelRepository::class)]
#[UniqueEntity(fields: ['domain'], message: 'dns.domain.unique')]
#[ORM\UniqueConstraint(fields: ['domain'])]
class ChannelWhiteLabel implements ChannelWhiteLabelInterface, SyncableInterface
{
use ChannelWhiteLabelMethodTrait;
#[ORM\Id, ORM\GeneratedValue(strategy: 'CUSTOM'), ORM\CustomIdGenerator(class: UuidGenerator::class), ORM\Column(type: 'string', length: 36)]
#[Serial\Groups(['Sync'])]
private ?string $id = null;
#[ORM\OneToOne(inversedBy: 'whiteLabel', targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups(groups: ['Sync'])]
private ?Channel $channel = null;
#[ORM\Column(type: 'string', length: 255, nullable: false)]
#[
Assert\NotBlank(),
Assert\Length(min: 2, max: 255),
DomainResolutionConstraint
]
#[Serial\Groups(['Sync'])]
private ?string $domain = null;
public static function getSyncKey(): string
{
return EntityKeys::CHANNEL_WHITE_LABEL;
}
public function getSyncDisplayLabel(): string
{
return $this->getChannel() . ' - ' . $this->getDomain();
}
}