<?php
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 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(fields: ['insured', 'insurer'])]
#[ApiResource(
iri: 'InsuredInsurerGlobal',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insured_insurer_global:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insured_insurer_global:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insured_insurer_global:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['insured_insurer_global:collection:get', 'createdAt'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insured_insurer_global:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insured_insurer_global:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'insured' => 'exact',
'insurer' => 'exact'
])]
class InsuredInsurerGlobal
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups([
'insured_insurer_global:collection:get',
'insured_insurer_global:item:get',
'insured:item:get',
])]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups([
'insured_insurer_global:collection:get',
'insured_insurer_global:item:get',
'insured:item:get',
])]
private $name;
#[ORM\ManyToOne(targetEntity: Insured::class, inversedBy: 'insurerGlobals')]
#[Groups([
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
'insurer:collection:post',
])]
#[MaxDepth(1)]
private $insured;
#[ORM\ManyToOne(targetEntity: Insurer::class, inversedBy: 'insuredGlobals')]
#[Groups([
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
])]
#[MaxDepth(1)]
private $insurer;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups([
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
'insured:item:get',
'insured:item:put',
])]
private $approvedLimit;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups([
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
'insured:item:get',
'insured:item:put',
])]
private $availableLimit;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups([
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
'insured:item:get',
'insured:item:put',
])]
private $usedLimit;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups([
'import:insurer',
'import:insured',
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
'insured:item:get',
'insured:item:put',
])]
private $comissionRate;
#[ORM\Column(type: 'datetime', nullable: true)]
#[Groups([
'import:insurer',
'import:insured',
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
'insured:item:get',
'insured:item:put',
])]
private $endTime;
#[ApiProperty()]
#[Groups([
'insured:item:get',
'insured_insurer_global:collection:get',
])]
private $insuredName;
#[ApiProperty()]
#[Groups([
'insured:item:get',
'insured_insurer_global:collection:get',
])]
private $insurerId;
#[ApiProperty()]
#[Groups([
'insured:item:get',
'insured_insurer_global:collection:get',
])]
private $insurerName;
#[ApiProperty()]
#[Groups([
'import:insured',
'insured:item:get',
'insured_insurer_global:collection:get',
])]
private $insurerTaxID;
#[ApiProperty()]
#[Groups([
'import:insurer',
])]
private $insuredTaxID;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/Text')]
#[Assert\Type('string')]
#[Groups([
'import:insurer',
'import:insured',
'insured_insurer_global:collection:get',
'insured_insurer_global:collection:post',
'insured_insurer_global:item:get',
'insured_insurer_global:item:put',
'insured:item:get',
'insured:item:put',
])]
private ?string $status = null;
#[ORM\OneToMany(mappedBy: 'insuredInsurerGlobal', targetEntity: InsuredInsurerGlobalCcg::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[Groups([
'insured:item:get',
'insured_insurer_global:item:get',
])]
#[MaxDepth(1)]
private $ccgs;
#[ORM\Column(type: 'text', nullable: true)]
private $observations;
public function __construct()
{
$this->ccgs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setName(): void
{
$this->name = "{$this->getInsuredName()} / {$this->getInsurerName()}";
}
public function getName(): ?string
{
return $this->name;
}
public function getInsured(): ?Insured
{
return $this->insured;
}
public function setInsured(?Insured $insured): self
{
$this->insured = $insured;
return $this;
}
public function getInsurer(): ?Insurer
{
return $this->insurer;
}
public function setInsurer(?Insurer $insurer): self
{
$this->insurer = $insurer;
return $this;
}
public function getApprovedLimit(): ?float
{
return $this->approvedLimit;
}
public function setApprovedLimit(?float $approvedLimit): self
{
$this->approvedLimit = $approvedLimit;
return $this;
}
public function getAvailableLimit(): ?float
{
return $this->availableLimit;
}
public function setAvailableLimit(?float $availableLimit): self
{
$this->availableLimit = $availableLimit;
return $this;
}
public function getUsedLimit(): ?float
{
return $this->usedLimit;
}
public function setUsedLimit(?float $usedLimit): self
{
$this->usedLimit = $usedLimit;
return $this;
}
public function getComissionRate(): ?float
{
return $this->comissionRate;
}
public function setComissionRate(?float $comissionRate): self
{
$this->comissionRate = $comissionRate;
return $this;
}
public function getEndTime(): ?\DateTimeInterface
{
return $this->endTime;
}
public function setEndTime(?\DateTimeInterface $endTime): self
{
$this->endTime = $endTime;
return $this;
}
public function getInsuredName(): ?string
{
return $this->getInsured()->getName();
}
public function getInsurerId(): ?int
{
return $this->getInsurer()->getId();
}
public function getInsurerName(): ?string
{
return $this->getInsurer()->getName();
}
public function getInsurerTaxID(): ?string
{
return $this->getInsurer()->getTaxID();
}
public function getInsuredTaxID(): ?string
{
return $this->getInsured()?->getTaxID();
}
/**
* @param string|null $status
*/
public function setStatus($status): self
{
$this->status = $status;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
/**
* @return Collection|InsuredInsurerGlobalCcg[]
*/
public function getCcgs(): Collection
{
return $this->ccgs;
}
public function addCcg(InsuredInsurerGlobalCcg $ccg): self
{
if (!$this->ccgs->contains($ccg)) {
$this->ccgs[] = $ccg;
$ccg->setInsuredInsurerGlobal($this);
}
return $this;
}
public function removeCcg(InsuredInsurerGlobalCcg $ccg): self
{
if ($this->ccgs->removeElement($ccg)) {
// set the owning side to null (unless already changed)
if ($ccg->getInsuredInsurerGlobal() === $this) {
$ccg->setInsuredInsurerGlobal(null);
}
}
return $this;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setObservations(?string $observations): self
{
$this->observations = $observations;
return $this;
}
}