<?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 ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use EasyRdf\Literal\Boolean;
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: 'Vessel',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'vessel:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'vessel:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'vessel:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => ['groups' => ['vessel:collection:get', 'createdAt'], 'enable_max_depth' => true],
],
'post' => [
'normalization_context' => ['groups' => 'vessel:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'vessel:collection:post', 'enable_max_depth' => true],
],
],
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'vesselName' => 'partial',
'imoNumber' => 'partial',
'vesselType' => 'exact',
'dwt' => 'partial',
'yearBuilt' => 'exact',
'imoClass' => 'partial',
'tankCoating' => 'exact',
'createdAt' => 'start'
],
)]
#[ApiFilter(
OrderFilter::class,
properties: [
'vesselName',
'imoNumber',
'vesselType',
'dwt',
'yearBuilt',
'imoClass',
'nitrogenGenerator',
'boxShape',
'openHatch',
'tankCoating',
'createdAt'
],
)]
#[ApiFilter(
BooleanFilter::class,
properties: [
'nitrogenGenerator',
'boxShape',
'openHatch',
],
)]
#[ApiFilter(PropertyFilter::class)]
class Vessel
{
use TimestampableEntity;
public const VESSEL_TYPES = [
'Tanker',
'Bulker'
];
public const TANKER_TYPES = [
'Chemical & Oil Carrier',
'Product Carrier',
'Chemical Bulk Tanker',
'Chemical Parcell Tanker',
'Asphalt & Bitumen Carrier',
'Methanol Carrier',
'Chemical Unknown Carrier',
'Tanker',
'Shuttle Tanker',
'Oil Bunkering Tanker',
'Products/Multi-Purpose',
'Cargo'
];
public const BULKER_TYPES = [
'Aggregates Carrier',
'Bulk Carrier',
'Cement Carrier',
'Deck Cargo Carrier',
'General Cargo',
'Gypsum Carrier',
'Heavy Lift Cargo Vessel',
'Limestone Carrier',
'Livestock Carrier',
'Open Hatch Carrier',
'Ore & Sulphuric Acid Carrier',
'Ore Carrier',
'Ore/Oil Carrier',
'Salt Carrier',
'Urea Carrier',
];
public const TANK_COATING = [
"Epoxy",
"Zinc",
"Stainless",
"Adv. Polymer"
];
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
#[ApiProperty(iri: 'https://schema.org/identifier')]
#[Groups(['vessel:collection:get', 'vessel:item:get'])]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/vesselName')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put', 'contract:item:get', 'contract:item:put', 'contract:collection:get', 'contract:collection:post'])]
private ?string $vesselName = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/imoNumber')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?string $imoNumber = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[Assert\Choice(choices: self::VESSEL_TYPES, message: 'The type is not valid.')]
#[ApiProperty(iri: 'https://schema.org/vesselType')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?string $vesselType = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\Type('string')]
#[Assert\Choice(choices: self::TANKER_TYPES, message: 'The type is not valid.')]
#[ApiProperty(iri: 'https://schema.org/tankerType')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?string $tankerType = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\Type('string')]
#[Assert\Choice(choices: self::BULKER_TYPES, message: 'The type is not valid.')]
#[ApiProperty(iri: 'https://schema.org/bulkerType')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?string $bulkerType = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/tankCoating')]
#[Assert\Type('string')]
#[Assert\Choice(choices: self::TANK_COATING, message: 'The option is not valid.')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?string $tankCoating = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[ApiProperty(iri: 'https://schema.org/dwt')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?string $dwt = null;
#[ORM\Column(type: 'integer', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('integer')]
#[ApiProperty(iri: 'https://schema.org/yearBuilt')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?int $yearBuilt = null;
// #[ORM\ManyToMany(targetEntity: 'App\Entity\Document')]
// #[ORM\InverseJoinColumn(unique: true)]
// #[ApiProperty(iri: 'https://schema.org/Document')]
// #[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
// private Collection $documents;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Owner', inversedBy: 'vessels')]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Owner')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
#[MaxDepth(1)]
private ?Owner $owner = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/observations')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?string $observations = null;
#[ORM\Column(type: 'boolean', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/BoxShape')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?bool $boxShape = null;
#[ORM\Column(type: 'boolean', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/OpenHatch')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?bool $openHatch = null;
#[ORM\Column(type: 'boolean', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/NitrogenGenerator')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?bool $nitrogenGenerator = null;
#[ORM\Column(type: 'integer', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/imoClass')]
#[Assert\Type('integer')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
private ?int $imoClass = null;
#[ORM\OneToMany(targetEntity: 'App\Entity\Contract', mappedBy: 'vessel')]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
#[MaxDepth(1)]
private ?Collection $contracts = null;
// #[ORM\OneToMany(targetEntity: 'App\Entity\Lifting', mappedBy: 'vessel')]
// #[ApiProperty(iri: 'https://schema.org/Lifting')]
// #[Groups(['vessel:collection:get', 'vessel:collection:post', 'vessel:item:get', 'vessel:item:put'])]
// #[MaxDepth(1)]
// private ?Collection $liftings = null;
public function __construct()
{
$this->id = Uuid::uuid4();
// $this->documents = new ArrayCollection();
$this->contracts = new ArrayCollection();
// $this->liftings = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setVesselName(?string $vesselName): void
{
$this->vesselName = $vesselName;
}
public function getVesselName(): ?string
{
return $this->vesselName;
}
public function setImoNumber(?string $imoNumber): void
{
$this->imoNumber = $imoNumber;
}
public function getImoNumber(): ?string
{
return $this->imoNumber;
}
public function setVesselType(?string $vesselType): void
{
$this->vesselType = $vesselType;
}
public function getVesselType(): ?string
{
return $this->vesselType;
}
public function setDwt(?string $dwt): void
{
$this->dwt = $dwt;
}
public function getDwt(): ?string
{
return $this->dwt;
}
public function setYearBuilt(?int $yearBuilt): void
{
$this->yearBuilt = $yearBuilt;
}
public function getYearBuilt(): ?int
{
return $this->yearBuilt;
}
public function setTankerType(?string $tankerType): void
{
$this->tankerType = $tankerType;
}
public function getTankerType(): ?string
{
return $this->tankerType;
}
public function setBulkerType(?string $bulkerType): void
{
$this->bulkerType = $bulkerType;
}
public function getBulkerType(): ?string
{
return $this->bulkerType;
}
// public function addDocument(Document $document): void
// {
// $this->documents[] = $document;
// }
// public function removeDocument(Document $document): void
// {
// $this->documents->removeElement($document);
// }
// public function getDocuments(): Collection
// {
// return $this->documents;
// }
public function setOwner(?Owner $owner): void
{
$this->owner = $owner;
}
public function getOwner(): ?Owner
{
return $this->owner;
}
public function setObservations(?string $observations): void
{
$this->observations = $observations;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setBoxShape(?bool $boxShape): void
{
$this->boxShape = $boxShape;
}
public function getBoxShape(): ?bool
{
return $this->boxShape;
}
public function setOpenHatch(?bool $openHatch): void
{
$this->openHatch = $openHatch;
}
public function getOpenHatch(): ?bool
{
return $this->openHatch;
}
public function setNitrogenGenerator(?bool $nitrogenGenerator): void
{
$this->nitrogenGenerator = $nitrogenGenerator;
}
public function getNitrogenGenerator(): ?bool
{
return $this->nitrogenGenerator;
}
public function setImoClass(?int $imoClass): void
{
$this->imoClass = $imoClass;
}
public function getImoClass(): ?int
{
return $this->imoClass;
}
public function setTankCoating(?string $tankCoating): void
{
$this->tankCoating = $tankCoating;
}
public function getTankCoating(): ?string
{
return $this->tankCoating;
}
public function getContracts(): Collection
{
return $this->contracts;
}
public function addContract(Contract $contract): self
{
if (!$this->contracts->contains($contract)) {
$this->contracts[] = $contract;
$contract->setVessel($this);
}
return $this;
}
public function removeContract(Contract $contract): self
{
if ($this->contracts->removeElement($contract)) {
if ($contract->getVessel() === $this) {
$contract->setVessel(null);
}
}
return $this;
}
// public function getLiftings(): Collection
// {
// return $this->liftings;
// }
// public function addLifting(Lifting $lifting): self
// {
// if (!$this->liftings->contains($lifting)) {
// $this->liftings[] = $lifting;
// $lifting->setVessel($this);
// }
// return $this;
// }
// public function removeLifting(Lifting $lifting): self
// {
// if ($this->liftings->removeElement($lifting)) {
// if ($lifting->getVessel() === $this) {
// $lifting->setVessel(null);
// }
// }
// return $this;
// }
}