<?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;
#[ORM\Entity]
#[ApiResource(
iri: 'PortCall',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "is_granted('ROLE_USER')",
'method' => 'GET',
'path' => '/contracts/ports/{id}',
'openapi_context' => [
'tags' => ['Contract / Port']
]
]
],
attributes: ['pagination_enabled' => false]
)]
class PortCall
{
use TimestampableEntity;
public const PORT_CALL_TYPE_LOAD = 'Load';
public const PORT_CALL_TYPE_DISCHARGE = 'Discharge';
public const PORT_CALL_TYPES = [
self::PORT_CALL_TYPE_LOAD,
self::PORT_CALL_TYPE_DISCHARGE
];
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty()]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Assert\Choice(
choices: self::PORT_CALL_TYPES,
message: 'The type is not valid.'
)]
#[Groups([
'contract:item:get',
'contract:item:put',
'contract:collection:get',
'contract:collection:post'
])]
private ?string $portCallType = null;
#[ORM\Column(type: 'datetime', nullable: true)]
#[ApiProperty()]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[Groups([
'contract:item:get',
'contract:item:put',
// 'contract:collection:get',
'contract:collection:post'
])]
private ?\DateTimeInterface $arrival = null;
#[ApiProperty()]
#[Groups([
'contract:item:get'
])]
private ?string $arrivalDate = null;
#[ApiProperty()]
#[Groups([
'contract:item:get'
])]
private ?string $arrivalTime = null;
#[ORM\Column(type: 'datetime', nullable: true)]
#[ApiProperty()]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[Groups([
'contract:item:get',
'contract:item:put',
// 'contract:collection:get',
'contract:collection:post'
])]
private ?\DateTimeInterface $berthing = null;
#[ApiProperty()]
#[Groups([
'contract:item:get'
])]
private ?string $berthingDate = null;
#[ApiProperty()]
#[Groups([
'contract:item:get'
])]
private ?string $berthingTime = null;
#[ORM\Column(type: 'datetime', nullable: true)]
#[ApiProperty()]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[Groups([
'contract:item:get',
'contract:item:put',
// 'contract:collection:get',
'contract:collection:post'
])]
private ?\DateTimeInterface $departure = null;
#[ApiProperty()]
#[Groups([
'contract:item:get'
])]
private ?string $departureDate = null;
#[ApiProperty()]
#[Groups([
'contract:item:get'
])]
private ?string $departureTime = null;
#[ORM\ManyToOne(
targetEntity: Port::class,
inversedBy: 'portCalls'
)]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty()]
#[Groups([
'contract:item:get',
'contract:item:put',
'contract:collection:get',
'contract:collection:post'
])]
#[MaxDepth(1)]
private ?Port $port = null;
#[ORM\Column(type: 'integer')]
#[Assert\NotNull]
#[ApiProperty()]
#[Groups([
'contract:item:get',
'contract:item:put',
'contract:collection:get',
'contract:collection:post'
])]
private ?int $portIndex = 0;
#[ORM\ManyToOne(
targetEntity: Contract::class,
inversedBy: 'portCalls'
)]
#[ORM\JoinColumn(nullable: true)]
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 setPortIndex(?int $portIndex): void
{
$this->portIndex = $portIndex;
}
public function getPortIndex(): ?int
{
return $this->portIndex;
}
public function setContract(?Contract $contract): void
{
$this->contract = $contract;
}
public function getContract(): ?Contract
{
return $this->contract;
}
}