<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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;
/**
* Represents an incident report.
*
* @see https://schema.org/Thing
*/
#[ORM\Entity]
#[ApiResource(
iri: 'incident',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'incident:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'incident:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'incident:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['incident:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'incident:collection:post', 'enable_max_depth' => true],
'denormalization_context' => [
'groups' => 'incident:collection:post',
'enable_max_depth' => true,
],
],
],
)]
class Incident
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
#[ApiProperty(iri: 'https://schema.org/identifier')]
#[Groups(['incident:item:get', 'incident:collection:get'])]
private ?UuidInterface $id = null;
/** @see _:category */
#[ORM\OneToOne(targetEntity: 'App\Entity\IncidentCategory')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['incident:item:get', 'incident:collection:get', 'incident:item:put', 'incident:collection:post'])]
private ?IncidentCategory $category = null;
/** @see _:subcategory */
#[ORM\OneToOne(targetEntity: 'App\Entity\IncidentSubcategory')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['incident:item:get', 'incident:collection:get', 'incident:item:put', 'incident:collection:post'])]
private ?IncidentSubcategory $subcategory = null;
/**
* A description of the incident.
*
* @see https://schema.org/description
*/
#[ORM\Column(type: 'text', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/description')]
#[Assert\NotBlank]
#[Groups(['incident:item:get', 'incident:collection:get', 'incident:item:put', 'incident:collection:post'])]
private ?string $description = null;
/**
* The date and time when the incident occurred.
*
* @see _:occurredAt
*/
#[ORM\Column(type: 'datetime', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/DateTime')]
#[Assert\NotNull]
#[Groups(['incident:item:get', 'incident:collection:get', 'incident:item:put', 'incident:collection:post'])]
private ?\DateTimeInterface $occurredAt = null;
/** @see _:relatedEntities */
#[ORM\ManyToMany(targetEntity: 'App\Entity\RelatedEntity')]
#[ORM\InverseJoinColumn(unique: true)]
#[Groups(['incident:item:get', 'incident:collection:get', 'incident:item:put', 'incident:collection:post'])]
private Collection $relatedEntities;
/** @see _:documents */
#[ORM\ManyToMany(targetEntity: 'App\Entity\Document')]
#[ORM\InverseJoinColumn(unique: true)]
#[Groups(['incident:item:get', 'incident:collection:get', 'incident:item:put', 'incident:collection:post'])]
private Collection $documents;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->relatedEntities = new ArrayCollection();
$this->documents = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setCategory(?IncidentCategory $category): void
{
$this->category = $category;
}
public function getCategory(): ?IncidentCategory
{
return $this->category;
}
public function setSubcategory(?IncidentSubcategory $subcategory): void
{
$this->subcategory = $subcategory;
}
public function getSubcategory(): ?IncidentSubcategory
{
return $this->subcategory;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setOccurredAt(?\DateTimeInterface $occurredAt): void
{
$this->occurredAt = $occurredAt;
}
public function getOccurredAt(): ?\DateTimeInterface
{
return $this->occurredAt;
}
public function addRelatedEntity(RelatedEntity $relatedEntity): void
{
if (!$this->relatedEntities->contains($relatedEntity)) {
$this->relatedEntities[] = $relatedEntity;
}
}
public function removeRelatedEntity(RelatedEntity $relatedEntity): void
{
$this->relatedEntities->removeElement($relatedEntity);
}
public function getRelatedEntities(): Collection
{
return $this->relatedEntities;
}
public function addDocument(Document $document): void
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
}
}
public function removeDocument(Document $document): void
{
$this->documents->removeElement($document);
}
public function getDocuments(): Collection
{
return $this->documents;
}
}