<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
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;
/**
* Represents a contact person within an organization.
*
* @see https://schema.org/Person
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Contact',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'contact:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'contact:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'contact:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['contact:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'contact:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'contact:collection:post', 'enable_max_depth' => true],
],
],
)]
#[ApiFilter(SearchFilter::class, properties: [
'charterer' => 'exact',
'contactName' => 'partial',
'createdAt' => 'start',
])]
#[ApiFilter(OrderFilter::class, properties: [
'contactName',
'createdAt'
])]
class Contact
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
// #[ApiProperty(iri: 'https://schema.org/identifier')]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/phoneNumber')]
#[Assert\Length(max: 255)]
#[Groups(['contact:collection:get', 'contact:collection:post', 'contact:item:get', 'contact:item:put', 'charterer:item:get'])]
private ?string $phoneNumbers = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/email')]
##[Assert\Email]
#[Groups(['contact:collection:get', 'contact:collection:post', 'contact:item:get', 'contact:item:put', 'charterer:item:get'])]
private ?string $emails = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/name')]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Groups(['contact:collection:get', 'contact:collection:post', 'contact:item:get', 'contact:item:put', 'charterer:item:get'])]
private ?string $contactName = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/position')]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Groups(['contact:collection:get', 'contact:collection:post', 'contact:item:get', 'contact:item:put', 'charterer:item:get'])]
private ?string $position = null;
// #[ORM\ManyToOne(targetEntity: 'App\Entity\Charterer', inversedBy: 'contacts')]
// #[ORM\JoinColumn(nullable: true)]
// #[ApiProperty(iri: 'https://schema.org/charterer')]
// #[Groups(['contact:item:get', 'contact:item:put', 'contact:collection:get', 'contact:collection:post'])]
// #[MaxDepth(1)]
// private ?Charterer $charterer = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setPhoneNumbers(?string $phoneNumbers): void
{
$this->phoneNumbers = $phoneNumbers;
}
public function getPhoneNumbers(): ?string
{
return $this->phoneNumbers;
}
public function setEmails(?string $emails): void
{
$this->emails = $emails;
}
public function getEmails(): ?string
{
return $this->emails;
}
public function setContactName(?string $contactName): void
{
$this->contactName = $contactName;
}
public function getContactName(): ?string
{
return $this->contactName;
}
public function setPosition(?string $position): void
{
$this->position = $position;
}
public function getPosition(): ?string
{
return $this->position;
}
// public function setCharterer(?Charterer $charterer): void
// {
// $this->charterer = $charterer;
// }
// public function getCharterer(): ?Charterer
// {
// return $this->charterer;
// }
}