<?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\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity]
#[UniqueEntity('taxID')]
#[ApiResource(
iri: 'Insured',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_ADMIN')",
'normalization_context' => [
'groups' => 'insured:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insured:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insured:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['insured:collection:get', 'createdAt'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insured:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insured:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'broker' => 'exact',
'taxID' => 'start',
'name' => 'partial',
'legalName' => 'partial',
'createdAt' => 'start',
])]
#[ApiFilter(OrderFilter::class, properties: [
'name',
'taxID',
'createdAt'
])]
class Insured
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
#[Groups([
'insured:collection:get',
'insured:item:get',
'demand:item:put',
'user:collection:post',
'user:item:put',
])]
private ?int $id = null;
/**
* The name of the item.
*
* @see https://schema.org/name
*/
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/name')]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:get',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:collection:get',
'demand:item:get',
'insured_insurer:collection:get',
'insured_insurer:item:get',
'insured_insurer:item:put',
'policy:collection:get',
'user:item:get',
'broker:item:get',
])]
private ?string $name = null;
#[ORM\Column(type: 'string')]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $zipcode = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $address = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $complement = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $neighborhood = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $city = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $state = null;
/**
* Email address.
*
* @see https://schema.org/email
*/
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/email')]
#[Assert\Email]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $email = null;
/**
* The official name of the organization, e.g. the registered company name.
*
* @see https://schema.org/legalName
*/
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/legalName')]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:get',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $legalName = null;
/**
* The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain.
*
* @see https://schema.org/taxID
*/
#[ORM\Column(type: 'string', unique: true)]
#[ApiProperty(iri: 'https://schema.org/taxID')]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:get',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
'demand:item:get',
'policy:item:get',
'demand:collection:get',
'policy:collection:get',
'user:item:get',
'broker:item:get',
])]
private ?string $taxID = null;
/**
* The telephone number.
*
* @see https://schema.org/telephone
*/
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/telephone')]
#[Assert\Type('string')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $telephone = null;
/**
* @var string|null the larger organization that this organization is a \[\[subOrganization\]\] of, if any
*
* @see https://schema.org/parentOrganization
*/
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/parentOrganization')]
#[Groups([
'import:insured',
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
private ?string $parentOrganization = null;
#[ORM\OneToMany(mappedBy: 'insured', targetEntity: InsuredUpload::class, cascade: ["remove"], orphanRemoval: true)]
#[Groups([
'insured:item:get',
])]
#[MaxDepth(1)]
private $uploads;
#[ORM\OneToMany(mappedBy: 'insured', targetEntity: Demand::class, cascade: ["remove"], orphanRemoval: true)]
private $demands;
#[ORM\OneToMany(mappedBy: 'insured', targetEntity: Policy::class, cascade: ["remove"], orphanRemoval: true)]
private $policies;
#[ORM\OneToMany(mappedBy: 'insured', targetEntity: InsuredInsurer::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[ORM\OrderBy(["name" => "ASC"])]
#[Groups([
// 'import:insured',
'insured:item:put',
])]
#[MaxDepth(1)]
private $insurers;
#[ORM\OneToMany(mappedBy: 'insured', targetEntity: InsuredInsurerGlobal::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[ORM\OrderBy(["name" => "ASC"])]
#[Groups([
// 'import:insured',
'insured:item:get',
'insured:item:put',
])]
#[MaxDepth(1)]
private $insurerGlobals;
#[ORM\OneToMany(mappedBy: 'insured', targetEntity: InsuredUser::class, cascade: ["remove"], orphanRemoval: true)]
#[Groups([
'import:insured',
'insured:item:get',
])]
#[MaxDepth(1)]
private $users;
#[ORM\OneToMany(mappedBy: 'insured', targetEntity: InsuredEmission::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[Groups([
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
#[MaxDepth(1)]
private $emissions;
#[ORM\ManyToOne(targetEntity: Broker::class, inversedBy: 'insureds')]
#[ApiProperty()]
#[Groups([
'insured:collection:post',
'insured:item:get',
'insured:item:put',
])]
#[MaxDepth(1)]
private $broker;
public function __construct()
{
$this->uploads = new ArrayCollection();
$this->demands = new ArrayCollection();
$this->policies = new ArrayCollection();
$this->insurers = new ArrayCollection();
$this->insurerGlobals = new ArrayCollection();
$this->users = new ArrayCollection();
$this->emissions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setName(?string $name): void
{
$this->name = $name;
}
public function getName(): ?string
{
return $this->name;
}
public function getZipcode(): ?string
{
return $this->zipcode;
}
public function setZipcode(?string $zipcode): self
{
$this->zipcode = $zipcode;
return $this;
}
public function setAddress(?string $address): void
{
$this->address = $address;
}
public function getAddress(): ?string
{
return $this->address;
}
public function getComplement(): ?string
{
return $this->complement;
}
public function setComplement(?string $complement): self
{
$this->complement = $complement;
return $this;
}
public function getNeighborhood(): ?string
{
return $this->neighborhood;
}
public function setNeighborhood(?string $neighborhood): self
{
$this->neighborhood = $neighborhood;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
public function setEmail(?string $email): void
{
$this->email = $email;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setLegalName(?string $legalName): void
{
$this->legalName = $legalName;
}
public function getLegalName(): ?string
{
return $this->legalName;
}
public function setTaxID(?string $taxID): void
{
$this->taxID = $taxID;
}
public function getTaxID(): ?string
{
return $this->taxID;
}
public function setTelephone(?string $telephone): void
{
$this->telephone = $telephone;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
/**
* @param string|null $parentOrganization
*/
public function setParentOrganization(?string $parentOrganization): void
{
$this->parentOrganization = $parentOrganization;
}
public function getParentOrganization(): ?string
{
return $this->parentOrganization;
}
/**
* @return Collection|InsuredUpload[]
*/
public function getUploads(): Collection
{
return $this->uploads;
}
public function addUpload(InsuredUpload $upload): self
{
if (!$this->uploads->contains($upload)) {
$this->uploads[] = $upload;
$upload->setInsured($this);
}
return $this;
}
public function removeUpload(InsuredUpload $upload): self
{
if ($this->uploads->removeElement($upload)) {
// set the owning side to null (unless already changed)
if ($upload->getInsured() === $this) {
$upload->setInsured(null);
}
}
return $this;
}
/**
* @return Collection|Demand[]
*/
public function getDemands(): Collection
{
return $this->demands;
}
public function addDemand(Demand $demand): self
{
if (!$this->demands->contains($demand)) {
$this->demands[] = $demand;
$demand->setInsured($this);
}
return $this;
}
public function removeDemand(Demand $demand): self
{
if ($this->demands->removeElement($demand)) {
// set the owning side to null (unless already changed)
if ($demand->getInsured() === $this) {
$demand->setInsured(null);
}
}
return $this;
}
/**
* @return Collection|Policy[]
*/
public function getPolicies(): Collection
{
return $this->policies;
}
public function addPolicy(Policy $policy): self
{
if (!$this->policies->contains($policy)) {
$this->policies[] = $policy;
$policy->setInsured($this);
}
return $this;
}
public function removePolicy(Policy $policy): self
{
if ($this->policies->removeElement($policy)) {
// set the owning side to null (unless already changed)
if ($policy->getInsured() === $this) {
$policy->setInsured(null);
}
}
return $this;
}
/**
* @return Collection|InsuredInsurer[]
*/
public function getInsurers(): Collection
{
return $this->insurers;
}
public function addInsurer(InsuredInsurer $insurer): self
{
if (!$this->insurers->contains($insurer)) {
$this->insurers[] = $insurer;
$insurer->setInsured($this);
}
return $this;
}
public function removeInsurer(InsuredInsurer $insurer): self
{
if ($this->insurers->removeElement($insurer)) {
// set the owning side to null (unless already changed)
if ($insurer->getInsured() === $this) {
$insurer->setInsured(null);
}
}
return $this;
}
/**
* @return Collection|InsuredInsurerGlobal[]
*/
public function getInsurerGlobals(): Collection
{
return $this->insurerGlobals;
}
public function addInsurerGlobal(InsuredInsurerGlobal $insurerGlobal): self
{
if (!$this->insurerGlobals->contains($insurerGlobal)) {
$this->insurerGlobals[] = $insurerGlobal;
$insurerGlobal->setInsured($this);
}
return $this;
}
public function removeInsurerGlobal(InsuredInsurerGlobal $insurerGlobal): self
{
if ($this->insurerGlobals->removeElement($insurerGlobal)) {
// set the owning side to null (unless already changed)
if ($insurerGlobal->getInsured() === $this) {
$insurerGlobal->setInsured(null);
}
}
return $this;
}
/**
* @return Collection|InsuredUser[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(InsuredUser $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setInsured($this);
}
return $this;
}
public function removeUser(InsuredUser $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getInsured() === $this) {
$user->setInsured(null);
}
}
return $this;
}
/**
* @return Collection|InsuredEmission[]
*/
public function getEmissions(): Collection
{
return $this->emissions;
}
public function addEmission(InsuredEmission $emission): self
{
if (!$this->emissions->contains($emission)) {
$this->emissions[] = $emission;
$emission->setInsured($this);
}
return $this;
}
public function removeEmission(InsuredEmission $emission): self
{
if ($this->emissions->removeElement($emission)) {
// set the owning side to null (unless already changed)
if ($emission->getInsured() === $this) {
$emission->setInsured(null);
}
}
return $this;
}
public function getBroker(): ?Broker
{
return $this->broker;
}
public function setBroker(?Broker $broker): self
{
$this->broker = $broker;
return $this;
}
}