<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
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 Symfony\Component\Serializer\Annotation\MaxDepth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* @see https://schema.org/Organization
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Charterer',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'charterer:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'charterer:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'charterer:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['charterer:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'charterer:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'charterer:collection:post', 'enable_max_depth' => true],
],
],
)]
#[ApiFilter(
SearchFilter::class,
properties: ['companyName' => 'partial', 'createdAt' => 'start'],
)]
#[ApiFilter(
OrderFilter::class,
properties: ['companyName', 'createdAt'],
)]
#[ApiFilter(PropertyFilter::class)]
class Charterer
{
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: false)]
#[ApiProperty(iri: 'https://schema.org/name')]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put', 'contract:item:get', 'contract:item:put', 'contract:collection:get', 'contract:collection:post'])]
private ?string $companyName = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/addressLine')]
#[Assert\Type('string')]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private ?string $addressLine1 = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/addressLine')]
#[Assert\Type('string')]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private ?string $addressLine2 = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/addressLine')]
#[Assert\Type('string')]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private ?string $addressLine3 = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/email')]
##[Assert\Email]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private ?string $charteringEmail = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/email')]
##[Assert\Email]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private ?string $operationsEmail = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/email')]
##[Assert\Email]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private ?string $accountingEmail = null;
// #[ORM\OneToMany(targetEntity: 'App\Entity\Contact', mappedBy: 'charterer', cascade: ['persist', 'remove'], orphanRemoval: true)]
// #[ApiProperty(iri: 'https://schema.org/Contact')]
// #[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get'])]
// #[MaxDepth(1)]
// private Collection $contacts;
// #[ORM\OneToOne(targetEntity: 'App\Entity\Contact')]
// #[ApiProperty(iri: 'https://schema.org/Contact')]
// #[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
// #[MaxDepth(1)]
// private ?Contact $primaryContact = null;
#[ORM\ManyToMany(targetEntity: 'App\Entity\Contract')]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private Collection $transactionHistory;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/observation')]
#[Assert\Type('string')]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
private ?string $observations = null;
#[ORM\OneToMany(targetEntity: 'App\Entity\Contract', mappedBy: 'charterer')]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['charterer:collection:get', 'charterer:collection:post', 'charterer:item:get', 'charterer:item:put'])]
#[MaxDepth(1)]
private ?Collection $contracts = null;
public function __construct()
{
$this->id = Uuid::uuid4();
// $this->contacts = new ArrayCollection();
$this->transactionHistory = new ArrayCollection();
$this->contracts = new ArrayCollection();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setCompanyName(?string $companyName): void
{
$this->companyName = $companyName;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setAddressLine1(?string $addressLine1): void
{
$this->addressLine1 = $addressLine1;
}
public function getAddressLine1(): ?string
{
return $this->addressLine1;
}
public function setAddressLine2(?string $addressLine2): void
{
$this->addressLine2 = $addressLine2;
}
public function getAddressLine2(): ?string
{
return $this->addressLine2;
}
public function setAddressLine3(?string $addressLine3): void
{
$this->addressLine3 = $addressLine3;
}
public function getAddressLine3(): ?string
{
return $this->addressLine3;
}
public function setCharteringEmail(?string $charteringEmail): void
{
$this->charteringEmail = $charteringEmail;
}
public function getCharteringEmail(): ?string
{
return $this->charteringEmail;
}
public function setOperationsEmail(?string $operationsEmail): void
{
$this->operationsEmail = $operationsEmail;
}
public function getOperationsEmail(): ?string
{
return $this->operationsEmail;
}
public function setAccountingEmail(?string $accountingEmail): void
{
$this->accountingEmail = $accountingEmail;
}
public function getAccountingEmail(): ?string
{
return $this->accountingEmail;
}
// public function addContact(Contact $contact): void
// {
// if (!$this->contacts->contains($contact)) {
// $this->contacts->add($contact);
// }
// }
// public function removeContact(Contact $contact): void
// {
// $this->contacts->removeElement($contact);
// }
// public function getContacts(): Collection
// {
// return $this->contacts;
// }
// public function setPrimaryContact(?Contact $primaryContact): void
// {
// $this->primaryContact = $primaryContact;
// }
// public function getPrimaryContact(): ?Contact
// {
// return $this->primaryContact;
// }
public function addTransactionHistory(Contract $transactionHistory): void
{
if (!$this->transactionHistory->contains($transactionHistory)) {
$this->transactionHistory->add($transactionHistory);
}
}
public function removeTransactionHistory(Contract $transactionHistory): void
{
$this->transactionHistory->removeElement($transactionHistory);
}
public function getTransactionHistory(): Collection
{
return $this->transactionHistory;
}
public function setObservations(?string $observations): void
{
$this->observations = $observations;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function getContracts(): Collection
{
return $this->contracts;
}
public function addContract(Contract $contract): self
{
if (!$this->contracts->contains($contract)) {
$this->contracts[] = $contract;
$contract->setCharterer($this);
}
return $this;
}
public function removeContract(Contract $contract): self
{
if ($this->contracts->removeElement($contract)) {
if ($contract->getCharterer() === $this) {
$contract->setCharterer(null);
}
}
return $this;
}
}