<?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: 'ReportedIncident',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'reported_incident:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'reported_incident:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'reported_incident:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['reported_incident:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'reported_incident:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'reported_incident:collection:post', 'enable_max_depth' => true],
],
],
)]
class ReportedIncident
{
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/category')]
#[Assert\NotBlank]
#[Assert\Type('string')]
// #[Assert\Choice(choices: self::PORT_CALL_TYPES, message: 'The type is not valid.')]
#[Groups(['reported_incident:item:get', 'reported_incident:item:put', 'reported_incident:collection:get', 'reported_incident:collection:post', 'contract:collection:post', 'contract:item:get', 'contract:item:put'])]
private ?string $category = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/subcategory')]
#[Assert\NotBlank]
#[Assert\Type('string')]
// #[Assert\Choice(choices: self::PORT_CALL_TYPES, message: 'The type is not valid.')]
#[Groups(['reported_incident:item:get', 'reported_incident:item:put', 'reported_incident:collection:get', 'reported_incident:collection:post', 'contract:collection:post', 'contract:item:get', 'contract:item:put'])]
private ?string $subcategory = null;
#[ORM\ManyToOne(targetEntity: 'App\Entity\Contract', inversedBy: 'reportedIncidents')]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['reported_incident:collection:get', 'reported_incident:collection:post', 'reported_incident:item:get', 'reported_incident:item:put'])]
#[MaxDepth(1)]
private ?Contract $contract = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setCategory(?string $category): void
{
$this->category = $category;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setSubcategory(?string $subcategory): void
{
$this->subcategory = $subcategory;
}
public function getSubcategory(): ?string
{
return $this->subcategory;
}
public function setContract(?Contract $contract): void
{
$this->contract = $contract;
}
public function getContract(): ?Contract
{
return $this->contract;
}
}