<?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\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
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;
#[ORM\Entity]
#[ApiResource(
iri: 'Demand',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'demand:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'demand:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'demand:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['demand:collection:get', 'endTime'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'demand:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'demand:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'insured' => 'exact',
'status' => 'exact',
'insured.name' => 'partial',
'insured.taxID' => 'start',
'processNumber' => 'start',
'limitValue' => 'start',
'policy.eligibleQuantity' => 'start',
'endTime' => 'start',
])]
// #[ApiFilter(DateFilter::class, properties: ['createdAt'])]
#[ApiFilter(ExistsFilter::class, properties: ['policy'])]
#[ApiFilter(OrderFilter::class, properties: [
'processNumber',
'status',
'endTime',
'insured.name',
'limitValue',
'policy.eligibleQuantity',
'insured.taxID',
'comissionRate',
'insurancePremium',
'prize',
])]
class Demand
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
#[Groups([
'demand:collection:get',
'demand:item:get',
])]
private ?int $id = null;
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
'policy:item:get',
])]
private ?string $processNumber = null;
/**
* The name of the item.
*
* @see https://schema.org/name
*/
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/name')]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderName = null;
#[ORM\Column(type: 'string')]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderZipcode = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderAddress = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderComplement = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderNeighborhood = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderCity = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderState = null;
#[ORM\Column(type: 'string')]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderTaxIDType = 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', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/taxID')]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $holderTaxID = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?float $interestFee = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:demand',
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?float $comissionRate = null;
#[ORM\Column(type: 'float')]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?float $limitValue = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:demand',
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?float $insurancePremium = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:demand',
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?float $prize = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Text')]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $pendingInformation = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/Text')]
#[Assert\Type('string')]
#[Groups([
'import:demand',
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private ?string $status = null;
#[ApiProperty(iri: 'https://schema.org/startTime')]
#[ORM\Column(type: 'datetime', nullable: true)]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private $startTime;
#[ApiProperty(iri: 'https://schema.org/endTime')]
#[ORM\Column(type: 'datetime')]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
private $endTime;
#[ORM\ManyToOne(targetEntity: Insured::class, inversedBy: 'demands')]
#[Groups([
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
#[MaxDepth(1)]
private $insured;
#[ApiProperty()]
#[Groups([
'import:demand',
])]
private $insuredTaxID;
#[ApiProperty()]
#[Groups([
'demand:collection:get',
'demand:item:get',
])]
#[MaxDepth(1)]
private $modality;
#[ApiProperty()]
#[Groups([
'import:demand',
])]
private $modalityName;
#[ORM\ManyToOne(targetEntity: Submodality::class)]
#[ORM\OrderBy(["name" => "ASC"])]
#[Groups([
'demand:collection:get',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
'policy:collection:get',
])]
#[MaxDepth(1)]
private $submodality;
#[ApiProperty()]
#[Groups([
'import:demand',
])]
private $submodalityName;
#[ORM\ManyToMany(targetEntity: Insurer::class, inversedBy: 'demands', cascade: ['persist'])]
#[Groups([
'import:demand',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
])]
#[MaxDepth(1)]
private $insurers;
#[ORM\OneToMany(mappedBy: 'demand', targetEntity: DemandUpload::class, cascade: ["remove"], orphanRemoval: true)]
#[Groups([
'demand:item:get',
])]
#[MaxDepth(1)]
private $uploads;
#[ORM\OneToOne(inversedBy: 'demand', targetEntity: Policy::class)]
#[Groups([
'demand:item:get',
'demand:collection:get',
])]
#[MaxDepth(1)]
private $policy = null;
public function __construct()
{
$this->insurers = new ArrayCollection();
$this->uploads = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @param string|null $processNumber
*/
public function setProcessNumber($processNumber): void
{
$this->processNumber = $processNumber;
}
public function getProcessNumber(): ?string
{
return $this->processNumber;
}
public function setHolderName(?string $holderName): void
{
$this->holderName = $holderName;
}
public function getHolderName(): ?string
{
return $this->holderName;
}
public function getHolderZipcode(): ?string
{
return $this->holderZipcode;
}
public function setHolderZipcode(?string $holderZipcode): self
{
$this->holderZipcode = $holderZipcode;
return $this;
}
public function setHolderAddress(?string $holderAddress): void
{
$this->holderAddress = $holderAddress;
}
public function getHolderAddress(): ?string
{
return $this->holderAddress;
}
public function getHolderComplement(): ?string
{
return $this->holderComplement;
}
public function setHolderComplement(?string $holderComplement): self
{
$this->holderComplement = $holderComplement;
return $this;
}
public function getHolderNeighborhood(): ?string
{
return $this->holderNeighborhood;
}
public function setHolderNeighborhood(?string $holderNeighborhood): self
{
$this->holderNeighborhood = $holderNeighborhood;
return $this;
}
public function getHolderCity(): ?string
{
return $this->holderCity;
}
public function setHolderCity(?string $holderCity): self
{
$this->holderCity = $holderCity;
return $this;
}
public function getHolderState(): ?string
{
return $this->holderState;
}
public function setHolderState(?string $holderState): self
{
$this->holderState = $holderState;
return $this;
}
public function setHolderTaxID(?string $holderTaxID): void
{
$this->holderTaxID = $holderTaxID;
}
public function getHolderTaxID(): ?string
{
return $this->holderTaxID;
}
public function setHolderTaxIDType(?string $holderTaxIDType): void
{
$this->holderTaxIDType = $holderTaxIDType;
}
public function getHolderTaxIDType(): ?string
{
return $this->holderTaxIDType;
}
/**
* @param float|null $interestFee
*/
public function setInterestFee($interestFee): void
{
$this->interestFee = $interestFee;
}
public function getInterestFee(): ?float
{
return $this->interestFee;
}
/**
* @param string|null $status
*/
public function setStatus($status): void
{
$this->status = $status;
}
public function getStatus(): ?string
{
return $this->status;
}
public function getInsured(): ?Insured
{
return $this->insured;
}
public function setInsured(?Insured $insured): self
{
$this->insured = $insured;
return $this;
}
public function getInsuredTaxID(): ?string
{
return $this->getInsured()->getTaxID();
}
public function getModality(): ?Modality
{
return $this->submodality?->getModality();
}
public function getModalityName(): ?string
{
return $this->getSubmodality()->getModality()->getName();
}
public function getSubmodality(): ?Submodality
{
return $this->submodality;
}
public function setSubmodality(?Submodality $submodality): self
{
$this->submodality = $submodality;
return $this;
}
public function getSubmodalityName(): ?string
{
return $this->getSubmodality()->getName();
}
/**
* @return Collection|Insurer[]
*/
public function getInsurers(): Collection
{
return $this->insurers;
}
public function addInsurer(Insurer $insurer): self
{
if (!$this->insurers->contains($insurer)) {
$this->insurers[] = $insurer;
}
return $this;
}
public function removeInsurer(Insurer $insurer): self
{
$this->insurers->removeElement($insurer);
return $this;
}
/**
* @return Collection|DemandUpload[]
*/
public function getUploads(): Collection
{
return $this->uploads;
}
public function addUpload(DemandUpload $upload): self
{
if (!$this->uploads->contains($upload)) {
$this->uploads[] = $upload;
$upload->setDemand($this);
}
return $this;
}
public function removeUpload(DemandUpload $upload): self
{
if ($this->uploads->removeElement($upload)) {
// set the owning side to null (unless already changed)
if ($upload->getDemand() === $this) {
$upload->setDemand(null);
}
}
return $this;
}
public function getStartTime(): ?\DateTimeInterface
{
return $this->startTime;
}
public function setStartTime(\DateTimeInterface $startTime): self
{
$this->startTime = $startTime;
return $this;
}
public function getEndTime(): ?\DateTimeInterface
{
return $this->endTime;
}
public function setEndTime(?\DateTimeInterface $endTime): self
{
$this->endTime = $endTime;
return $this;
}
public function getPolicy(): ?Policy
{
return $this->policy;
}
public function setPolicy(?Policy $policy): self
{
$this->policy = $policy;
return $this;
}
public function getComissionRate(): ?float
{
return $this->comissionRate;
}
public function setComissionRate(?float $comissionRate): self
{
$this->comissionRate = $comissionRate;
return $this;
}
public function getLimitValue(): ?float
{
return $this->limitValue;
}
public function setLimitValue(?float $limitValue): self
{
$this->limitValue = $limitValue;
return $this;
}
public function getInsurancePremium(): ?float
{
return $this->insurancePremium;
}
public function setInsurancePremium(?float $insurancePremium): self
{
$this->insurancePremium = $insurancePremium;
return $this;
}
public function getPrize(): ?float
{
return $this->prize;
}
public function setPrize(?float $prize): self
{
$this->prize = $prize;
return $this;
}
public function getPendingInformation(): ?string
{
return $this->pendingInformation;
}
public function setPendingInformation(?string $pendingInformation): self
{
$this->pendingInformation = $pendingInformation;
return $this;
}
}