<?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;
#[ORM\Entity]
#[ApiResource(
iri: 'Policy',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'policy:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'policy:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'policy:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['policy:collection:get', 'createdAt'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'policy:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'policy:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'insured' => 'exact',
'status' => 'exact',
'policyNumber' => 'start',
'insured.name' => 'partial',
'insured.taxID' => 'start',
'holderName' => 'partial',
'holderTaxID' => 'start',
'processNumber' => 'start',
'interestRate' => 'start',
'eligibleQuantity' => 'start',
'createdAt' => 'start',
])]
#[ApiFilter(OrderFilter::class, properties: [
'policyNumber',
'processNumber',
'status',
'createdAt',
'interestRate',
'eligibleQuantity',
'insured.taxID',
'insured.name',
'holderName',
'holderTaxID',
])]
class Policy
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
#[Groups([
'policy:collection:get',
'policy:item:get',
])]
private ?int $id = null;
#[ORM\Column(type: 'string')]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:item:get',
])]
private ?string $policyNumber = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
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:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderName = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderZipcode = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderAddress = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderComplement = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderNeighborhood = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderCity = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderState = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy: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:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $holderTaxID = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Text')]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $paymentMethod = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/description')]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?string $observations = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:collection:get',
])]
private ?float $eligibleQuantity = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/interestRate')]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:item:get',
])]
private ?float $interestRate = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:collection:get',
])]
private ?float $insurancePremium = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?float $interestFee = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:collection:get',
])]
private ?float $commission = null;
#[ORM\Column(type: 'boolean', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/Boolean')]
#[Assert\Type('boolean')]
#[Groups([
'import:policy',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
private ?bool $hasParentOrganization = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/Text')]
#[Assert\Type('string')]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:item:get',
])]
private ?string $status = null;
#[ORM\OneToMany(mappedBy: 'policy', targetEntity: Endorsement::class, cascade: ["remove"], orphanRemoval: true)]
#[Groups([
'policy:item:get',
])]
#[MaxDepth(1)]
private $endorsements;
#[ORM\OneToMany(mappedBy: 'policy', targetEntity: PolicyUpload::class, cascade: ["remove"], orphanRemoval: true)]
#[Groups([
'policy:item:get',
])]
#[MaxDepth(1)]
private $uploads;
#[ORM\OneToMany(mappedBy: 'policy', targetEntity: PolicyInsurer::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[Groups([
'import:policy',
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:item:get',
])]
#[MaxDepth(1)]
private $insurers;
#[ORM\ManyToOne(targetEntity: Insurer::class)]
#[Groups([
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'demand:item:get',
])]
#[MaxDepth(1)]
private $insurerLeader;
#[ApiProperty()]
#[Groups([
'import:insurer',
'insurer:item:get',
'insurer:collection:get',
'policy:collection:get',
])]
private $insurerLeaderName;
#[ApiProperty()]
#[Groups([
'import:policy',
])]
private $insurerLeaderTaxID;
#[ORM\ManyToOne(targetEntity: Insured::class, inversedBy: 'policies')]
#[Groups([
'policy:collection:post',
'policy:item:get',
'policy:item:put',
'policy:collection:get',
])]
#[MaxDepth(1)]
private $insured;
#[ApiProperty()]
#[Groups([
'import:policy',
])]
private $insuredTaxID;
#[ORM\OneToOne(mappedBy: 'policy', targetEntity: Demand::class, cascade: ["remove"], orphanRemoval: true)]
#[Groups([
'policy:collection:get',
'policy:collection:post',
'policy:item:get',
'policy:item:put',
])]
#[MaxDepth(1)]
private $demand;
#[ApiProperty()]
#[Groups([
'import:demand',
'demand:item:get',
'demand:collection:get',
'policy:collection:get',
])]
private $demandEndTime;
public function __construct()
{
$this->endorsements = new ArrayCollection();
$this->insurers = new ArrayCollection();
$this->uploads = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @param string|null $policyNumber
*/
public function setPolicyNumber($policyNumber): void
{
$this->policyNumber = $policyNumber;
}
public function getPolicyNumber(): ?string
{
return $this->policyNumber;
}
/**
* @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 $eligibleQuantity
*/
public function setEligibleQuantity($eligibleQuantity): void
{
$this->eligibleQuantity = $eligibleQuantity;
}
public function getEligibleQuantity(): ?float
{
return $this->eligibleQuantity;
}
/**
* @param float|null $interestRate
*/
public function setInterestRate($interestRate): void
{
$this->interestRate = $interestRate;
}
public function getInterestRate(): ?float
{
return $this->interestRate;
}
/**
* @param float|null $insurancePremium
*/
public function setInsurancePremium($insurancePremium): void
{
$this->insurancePremium = $insurancePremium;
}
public function getInsurancePremium(): ?float
{
return $this->insurancePremium;
}
/**
* @param float|null $interestFee
*/
public function setInterestFee($interestFee): void
{
$this->interestFee = $interestFee;
}
public function getInterestFee(): ?float
{
return $this->interestFee;
}
/**
* @param float|null $commission
*/
public function setCommission($commission): void
{
$this->commission = $commission;
}
public function getCommission(): ?float
{
return $this->commission;
}
/**
* @param bool|null $hasParentOrganization
*/
public function setHasParentOrganization($hasParentOrganization): void
{
$this->hasParentOrganization = $hasParentOrganization;
}
public function getHasParentOrganization(): ?bool
{
return $this->hasParentOrganization;
}
/**
* @param string|null $status
*/
public function setStatus($status): void
{
$this->status = $status;
}
public function getStatus(): ?string
{
return $this->status;
}
/**
* @return Collection|Endorsement[]
*/
public function getEndorsements(): Collection
{
return $this->endorsements;
}
public function addEndorsement(Endorsement $endorsement): self
{
if (!$this->endorsements->contains($endorsement)) {
$this->endorsements[] = $endorsement;
$endorsement->setPolicy($this);
}
return $this;
}
public function removeEndorsement(Endorsement $endorsement): self
{
if ($this->endorsements->removeElement($endorsement)) {
// set the owning side to null (unless already changed)
if ($endorsement->getPolicy() === $this) {
$endorsement->setPolicy(null);
}
}
return $this;
}
/**
* @return Collection|PolicyInsurer[]
*/
public function getInsurers(): Collection
{
return $this->insurers;
}
public function addInsurer(PolicyInsurer $insurer): self
{
if (!$this->insurers->contains($insurer)) {
$this->insurers[] = $insurer;
}
return $this;
}
public function removeInsurer(PolicyInsurer $insurer): self
{
$this->insurers->removeElement($insurer);
return $this;
}
public function getInsurerLeader(): ?Insurer
{
return $this->insurerLeader;
}
public function setInsurerLeader(?Insurer $insurerLeader): self
{
$this->insurerLeader = $insurerLeader;
return $this;
}
public function getInsurerLeaderName(): ?string
{
$insurerLeader = $this->getInsurerLeader();
if ($insurerLeader !== null) {
return $insurerLeader->getName();
}
return null;
}
public function getInsurerLeaderTaxID(): ?string
{
return $this->getInsurerLeader()?->getTaxID();
}
/**
* @return Collection|PolicyUpload[]
*/
public function getUploads(): Collection
{
return $this->uploads;
}
public function addUpload(PolicyUpload $upload): self
{
if (!$this->uploads->contains($upload)) {
$this->uploads[] = $upload;
$upload->setPolicy($this);
}
return $this;
}
public function removeUpload(PolicyUpload $upload): self
{
if ($this->uploads->removeElement($upload)) {
// set the owning side to null (unless already changed)
if ($upload->getPolicy() === $this) {
$upload->setPolicy(null);
}
}
return $this;
}
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 getDemand(): ?Demand
{
return $this->demand;
}
public function setDemand(?Demand $demand): self
{
// unset the owning side of the relation if necessary
if (null === $demand && null !== $this->demand) {
$this->demand->setPolicy(null);
}
// set the owning side of the relation if necessary
if (null !== $demand && $demand->getPolicy() !== $this) {
$demand->setPolicy($this);
}
$this->demand = $demand;
return $this;
}
public function getDemandEndTime(): ?\DateTimeInterface
{
$demand = $this->getDemand();
if ($demand !== null) {
return $demand->getEndTime();
}
return null;
}
public function getPaymentMethod(): ?string
{
return $this->paymentMethod;
}
public function setPaymentMethod(?string $paymentMethod): self
{
$this->paymentMethod = $paymentMethod;
return $this;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setObservations(?string $observations): self
{
$this->observations = $observations;
return $this;
}
}