<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Trait\TimestampableEntity;
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: 'PortCall',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'port_call:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'port_call:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'port_call:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['port_call:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'port_call:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'port_call:collection:post', 'enable_max_depth' => true],
],
],
)]
class PortCall
{
use TimestampableEntity;
public const PORT_CALL_TYPES = [
'Load',
'Discharge'
];
#[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/portCallType')]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Assert\Choice(choices: self::PORT_CALL_TYPES, message: 'The type is not valid.')]
#[Groups(['port_call:item:get', 'port_call:item:put', 'port_call:collection:get', 'port_call:collection:post', 'contract:collection:post', 'contract:item:get', 'contract:item:put'])]
private ?string $portCallType = null;
#[ORM\Column(type: 'datetime', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/arrival')]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[Groups(['contract:item:get', 'contract:item:put', 'contract:collection:get', 'contract:collection:post', 'contract:collection:post', 'contract:item:get', 'contract:item:put'])]
private ?\DateTimeInterface $arrival = null;
#[ApiProperty(iri: 'https://schema.org/arrivalDate')]
#[Groups(['contract:item:get'])]
private ?string $arrivalDate = null;
#[ApiProperty(iri: 'https://schema.org/arrivalTime')]
#[Groups(['contract:item:get'])]
private ?string $arrivalTime = null;
#[ORM\Column(type: 'datetime', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/berthing')]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[Groups(['contract:item:get', 'contract:item:put', 'contract:collection:get', 'contract:collection:post', 'contract:collection:post', 'contract:item:get', 'contract:item:put'])]
private ?\DateTimeInterface $berthing = null;
#[ApiProperty(iri: 'https://schema.org/berthingDate')]
#[Groups(['contract:item:get'])]
private ?string $berthingDate = null;
#[ApiProperty(iri: 'https://schema.org/berthingTime')]
#[Groups(['contract:item:get'])]
private ?string $berthingTime = null;
#[ORM\Column(type: 'datetime', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/departure')]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[Groups(['contract:item:get', 'contract:item:put', 'contract:collection:get', 'contract:collection:post', 'contract:collection:post', 'contract:item:get', 'contract:item:put'])]
private ?\DateTimeInterface $departure = null;
#[ApiProperty(iri: 'https://schema.org/departureDate')]
#[Groups(['contract:item:get'])]
private ?string $departureDate = null;
#[ApiProperty(iri: 'https://schema.org/departureTime')]
#[Groups(['contract:item:get'])]
private ?string $departureTime = null;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Port', inversedBy: 'portCalls')]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty(iri: 'https://schema.org/port')]
#[Groups(['port_call:collection:get', 'port_call:collection:post', 'port_call:item:get', 'port_call:item:put', 'contract:collection:post', 'contract:item:get', 'contract:item:put'])]
#[MaxDepth(1)]
private ?Port $port = null;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Contract', inversedBy: 'portCalls')]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['port_call:collection:get', 'port_call:collection:post', 'port_call:item:get', 'port_call:item:put'])]
#[MaxDepth(1)]
private ?Contract $contract = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setPortCallType(?string $portCallType): void
{
$this->portCallType = $portCallType;
}
public function getPortCallType(): ?string
{
return $this->portCallType;
}
public function setArrival(?\DateTimeInterface $arrival): void
{
$this->arrival = $arrival;
}
public function getArrival(): ?\DateTimeInterface
{
return $this->arrival;
}
public function getArrivalDate(): ?string
{
return $this->arrival ? $this->arrival->format('Y-m-d') : null;
}
public function getArrivalTime(): ?string
{
return $this->arrival ? $this->arrival->format('H:i') : null;
}
public function setBerthing(?\DateTimeInterface $berthing): void
{
$this->berthing = $berthing;
}
public function getBerthing(): ?\DateTimeInterface
{
return $this->berthing;
}
public function getBerthingDate(): ?string
{
return $this->berthing ? $this->berthing->format('Y-m-d') : null;
}
public function getBerthingTime(): ?string
{
return $this->berthing ? $this->berthing->format('H:i') : null;
}
public function setDeparture(?\DateTimeInterface $departure): void
{
$this->departure = $departure;
}
public function getDeparture(): ?\DateTimeInterface
{
return $this->departure;
}
public function getDepartureDate(): ?string
{
return $this->departure ? $this->departure->format('Y-m-d') : null;
}
public function getDepartureTime(): ?string
{
return $this->departure ? $this->departure->format('H:i') : null;
}
public function setPort(?Port $port): void
{
$this->port = $port;
}
public function getPort(): ?Port
{
return $this->port;
}
public function setContract(?Contract $contract): void
{
$this->contract = $contract;
}
public function getContract(): ?Contract
{
return $this->contract;
}
}