<?php
namespace App\Entity\Channel;
use App\Entity\Account\User;
use App\Repository\Channel\ServiceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
use Nellapp\Bundle\SDKBundle\Auth\Entity\UserInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Service\ServiceInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Service\ServiceMethodTrait;
use Nellapp\Bundle\SDKBundle\Permission\UsersResource\UsersResourceInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation as Serial;
#[ORM\Entity(repositoryClass: ServiceRepository::class)]
#[ORM\Table(name: 'channel_services')]
class Service implements TimestampInterface, ServiceInterface, UsersResourceInterface
{
use TimestampTrait;
use ServiceMethodTrait;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[Serial\Groups(groups: ['Service', 'Conversation', 'Api'])]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[
Assert\NotBlank(message: 'entity.channel.service.name.NotBlank'),
Assert\Length(
min: 2,
max: 255,
minMessage: 'entity.channel.service.name.min',
maxMessage: 'entity.channel.service.name.max',
)
]
#[Serial\Groups(groups: ['Service', 'Conversation', 'Api'])]
private ?string $label = null;
#[
ORM\ManyToMany(targetEntity: User::class, inversedBy: 'services'),
ORM\JoinTable('channel_service_users')
]
private Collection $users;
#[
ORM\ManyToOne(targetEntity: ChannelInterface::class),
ORM\JoinColumn(nullable: false),
]
private ?ChannelInterface $channel = null;
#[ORM\Column(type: 'boolean', nullable: false)]
private ?bool $enableOnNim = null;
public function __construct()
{
$this->users = new ArrayCollection();
}
public function hasUser(?UserInterface $user, array $tags = []): bool
{
if ($user === null) {
return false;
}
return $this->getUsers()->contains($user);
}
}