<?php
namespace App\Entity\Channel;
use App\Entity\Sync\SyncableInterface;
use App\Repository\Channel\RoomRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Room\RoomInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Room\RoomMethodTrait;
use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: RoomRepository::class),
ORM\Index(columns: ['name'], flags: ['fulltext']),
ORM\Table(name: 'channel_rooms')
]
class Room implements RoomInterface, SyncableInterface
{
use RoomMethodTrait;
#[ORM\Id, ORM\GeneratedValue(strategy: 'CUSTOM'), ORM\CustomIdGenerator(class: UuidGenerator::class), ORM\Column(type: 'string', length: 36)]
#[Serial\Groups(['Manager', 'Sync'])]
private ?string $id = null;
#[ORM\Column(type: 'string', length: 255, nullable: false)]
#[
Assert\NotBlank(message: 'room.name.NotBlank'),
Assert\Length(
min: 2,
max: 255,
minMessage: 'base.length.min',
maxMessage: 'base.length.max'
)
]
#[Serial\Groups(['Manager', 'Sync'])]
private ?string $name = null;
#[ORM\Column(type: 'integer', nullable: false)]
#[Assert\NotBlank(message: 'room.capacity.NotBlank')]
#[Serial\Groups(['Manager', 'Sync'])]
private ?int $capacity = null;
#[ORM\ManyToMany(targetEntity: Material::class, mappedBy: 'rooms')]
#[Serial\Groups(['Manager'])]
private ?Collection $materials;
#[ORM\ManyToOne(targetEntity: Place::class, inversedBy: 'rooms')]
#[ORM\JoinColumn(nullable: false)]
#[IdGroups(groups: ['Sync'])]
private ?Place $place = null;
public function __construct()
{
$this->materials = new ArrayCollection();
}
public static function getSyncKey(): string
{
return EntityKeys::CHANNEL_ROOM;
}
public function getSyncDisplayLabel(): string
{
return (string) $this->getName();
}
public function getMaterials(): Collection
{
return $this->materials;
}
public function addMaterial(Material $material): self
{
if (!$this->materials->contains($material)) {
$this->materials[] = $material;
$material->addRoom($this);
}
return $this;
}
public function removeMaterial(Material $material): self
{
if ($this->materials->contains($material)) {
$this->materials->removeElement($material);
$material->removeRoom($this);
}
return $this;
}
}