<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'DeliveryNotice',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "is_granted('ROLE_USER')",
"method" => "GET",
"path" => "/contracts/delivery_notices/{id}",
"openapi_context" => [
"tags" => ["Contract / DeliveryNotice"]
]
]
],
attributes: ["pagination_enabled" => false]
)]
class DeliveryNotice
{
use TimestampableEntity;
public const NOTICE_TYPE_APPROX = 'Approx';
public const NOTICE_TYPE_FIRM = 'Firm';
public const NOTICE_TYPES = [
self::NOTICE_TYPE_APPROX,
self::NOTICE_TYPE_FIRM,
];
public const NOTICE_STATUS_WAITING = 'WAITING';
public const NOTICE_STATUS_SENT = 'SENT';
public const NOTICE_STATUSES = [
self::NOTICE_STATUS_WAITING,
self::NOTICE_STATUS_SENT,
];
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'integer', nullable: true)]
#[ApiProperty()]
#[Assert\Type('integer')]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?int $noticeNumber = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[Assert\Choice(
choices: self::NOTICE_TYPES,
message: 'The type is not valid.'
)]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $noticeType = self::NOTICE_TYPE_APPROX;
#[ORM\Column(type: 'date', nullable: true)]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?\DateTimeInterface $noticeDate = null;
#[ORM\Column(type: 'boolean', nullable: true)]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'])]
private ?bool $sentToCharterer = false;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[Assert\Choice(
choices: self::NOTICE_STATUSES,
message: 'The status is not valid.'
)]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $status = self::NOTICE_STATUS_WAITING;
#[ORM\ManyToOne(
targetEntity: Contract::class,
inversedBy: 'deliveryNotices'
)]
#[ORM\JoinColumn(nullable: true)]
private ?Contract $contract = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setNoticeNumber(?int $noticeNumber): void
{
$this->noticeNumber = $noticeNumber;
}
public function getNoticeNumber(): ?int
{
return $this->noticeNumber;
}
public function setNoticeType(?string $noticeType): void
{
$this->noticeType = $noticeType;
}
public function getNoticeType(): ?string
{
return $this->noticeType;
}
public function setNoticeDate(?\DateTimeInterface $noticeDate): void
{
$this->noticeDate = $noticeDate;
}
public function getNoticeDate(): ?string
{
return $this->noticeDate?->format('Y-m-d');
}
public function getSentToCharterer(): ?bool
{
return $this->sentToCharterer ?? false;
}
public function setSentToCharterer(?bool $sentToCharterer): void
{
$this->sentToCharterer = $sentToCharterer;
}
public function setStatus(?string $status): void
{
$this->status = $status;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setContract(?Contract $contract): void
{
$this->contract = $contract;
}
public function getContract(): ?Contract
{
return $this->contract;
}
}