<?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 Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'OperationIncident',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "is_granted('ROLE_USER')",
'method' => 'GET',
'path' => '/contracts/operation_reports/incidents/{id}',
'openapi_context' => [
'tags' => ['Contract / OperationReport / OperationIncident']
]
]
],
attributes: ['pagination_enabled' => false]
)]
class OperationIncident
{
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()]
#[Assert\NotBlank]
#[Assert\Type('string')]
// #[Assert\Choice(
// choices: self::PORT_CALL_TYPES,
// message: 'The type is not valid.'
// )]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $category = 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:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $subcategory = null;
#[ORM\ManyToOne(
targetEntity: OperationReport::class,
inversedBy: 'operationIncidents'
)]
#[ORM\JoinColumn(nullable: true)]
private ?OperationReport $operationReport = 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 setOperationReport(?OperationReport $operationReport): void
{
$this->operationReport = $operationReport;
}
public function getOperationReport(): ?OperationReport
{
return $this->operationReport;
}
}