<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* @see https://schema.org/Thing
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Berth',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'berth:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'berth:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'berth:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => ['groups' => ['berth:collection:get', 'createdAt'], 'enable_max_depth' => true],
],
'post' => [
'normalization_context' => ['groups' => 'berth:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'berth:collection:post', 'enable_max_depth' => true],
],
],
)]
#[ApiFilter(
SearchFilter::class,
properties: ['port' => 'exact', 'berthName' => 'partial', 'createdAt' => 'start'],
)]
#[ApiFilter(
OrderFilter::class,
properties: ['berthName', 'createdAt'],
)]
class Berth
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/name')]
#[Assert\NotBlank]
#[Groups(['berth:collection:get', 'berth:collection:post', 'berth:item:get', 'berth:item:put', 'port:item:get'])]
private ?string $berthName = null;
// @deprecated
// #[ORM\ManyToMany(targetEntity: 'App\Entity\CargoType')]
// #[ApiProperty(iri: 'https://schema.org/CargoType')]
// #[Groups(['berth:collection:get', 'berth:collection:post', 'berth:item:get', 'berth:item:put'])]
// private Collection $cargoType;
#[ORM\ManyToMany(targetEntity: 'App\Entity\DockingRestriction')]
#[ApiProperty(iri: 'https://schema.org/DockeringRestriction')]
#[Groups(['berth:collection:get', 'berth:collection:post', 'berth:item:get', 'berth:item:put'])]
private Collection $dockingRestrictions;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/restrictionInfoSource')]
#[Assert\NotBlank]
#[Groups(['berth:collection:get', 'berth:collection:post', 'berth:item:get', 'berth:item:put'])]
private ?string $restrictionInfoSource = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/observations')]
#[Groups(['berth:collection:get', 'berth:collection:post', 'berth:item:get', 'berth:item:put'])]
private ?string $observations = null;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Port', inversedBy: 'berths')]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Port')]
#[Groups(['berth:item:get', 'berth:item:put', 'berth:collection:get', 'berth:collection:post'])]
#[MaxDepth(1)]
private ?Port $port = null;
public function __construct()
{
$this->id = Uuid::uuid4();
// $this->cargoType = new ArrayCollection();
$this->dockingRestrictions = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setBerthName(?string $berthName): void
{
$this->berthName = $berthName;
}
public function getBerthName(): ?string
{
return $this->berthName;
}
// public function addCargoType(CargoType $cargoType): void
// {
// if (!$this->cargoType->contains($cargoType)) {
// $this->cargoType[] = $cargoType;
// }
// }
// public function removeCargoType(CargoType $cargoType): void
// {
// $this->cargoType->removeElement($cargoType);
// }
// public function getCargoType(): Collection
// {
// return $this->cargoType;
// }
public function addDockingRestriction(DockingRestriction $dockingRestriction): void
{
if (!$this->dockingRestrictions->contains($dockingRestriction)) {
$this->dockingRestrictions[] = $dockingRestriction;
}
}
public function removeDockingRestriction(DockingRestriction $dockingRestriction): void
{
$this->dockingRestrictions->removeElement($dockingRestriction);
}
public function getDockingRestrictions(): Collection
{
return $this->dockingRestrictions;
}
public function setRestrictionInfoSource(?string $restrictionInfoSource): void
{
$this->restrictionInfoSource = $restrictionInfoSource;
}
public function getRestrictionInfoSource(): ?string
{
return $this->restrictionInfoSource;
}
public function setObservations(?string $observations): void
{
$this->observations = $observations;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setPort(?Port $port): void
{
$this->port = $port;
}
public function getPort(): ?Port
{
return $this->port;
}
}