<?php
// @deprecated
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 App\Trait\TimestampableEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @see https://schema.org/Organization
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Broker',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'broker:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'broker:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'broker:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => ['groups' => ['broker:collection:get', 'createdAt'], 'enable_max_depth' => true],
],
'post' => [
'normalization_context' => ['groups' => 'broker:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'broker:collection:post', 'enable_max_depth' => true],
],
],
)]
#[ApiFilter(
SearchFilter::class,
properties: ['companyName' => 'partial', 'createdAt' => 'start'],
)]
#[ApiFilter(
OrderFilter::class,
properties: ['companyName', 'createdAt'],
)]
class Broker
{
use TimestampableEntity;
#[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/name')]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Groups(['broker:collection:get', 'broker:collection:post', 'broker:item:get', 'broker:item:put', 'contract:collection:get'])]
private ?string $companyName = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/desk')]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Groups(['broker:collection:get', 'broker:collection:post', 'broker:item:get', 'broker:item:put'])]
private ?string $desk = null;
#[ORM\ManyToMany(targetEntity: 'App\Entity\Contact')]
#[ApiProperty(iri: 'https://schema.org/Contact')]
#[Groups(['broker:collection:get', 'broker:collection:post', 'broker:item:get', 'broker:item:put'])]
private Collection $contacts;
#[ORM\OneToOne(targetEntity: 'App\Entity\Contact')]
#[ApiProperty(iri: 'https://schema.org/Contact')]
#[Groups(['broker:collection:get', 'broker:collection:post', 'broker:item:get', 'broker:item:put'])]
private ?Contact $primaryContact = null;
#[ORM\ManyToMany(targetEntity: 'App\Entity\Contract')]
#[ORM\InverseJoinColumn(unique: true)]
#[ApiProperty(iri: 'https://schema.org/Contract')]
#[Groups(['broker:collection:get', 'broker:collection:post', 'broker:item:get', 'broker:item:put'])]
private ?Collection $contracts = null;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->contacts = 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 setDesk(?string $desk): void
{
$this->desk = $desk;
}
public function getDesk(): ?string
{
return $this->desk;
}
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 addContract(Contract $contract): void
{
$this->contracts[] = $contract;
}
public function removeContract(Contract $contract): void
{
$this->contracts->removeElement($contract);
}
public function getContracts(): Collection
{
return $this->contracts;
}
}