<?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: 'Insurer',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insurer:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insurer:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insurer:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['insurer:collection:get', 'createdAt'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insurer:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insurer:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'insureds.insured' => 'exact',
'taxID' => 'start',
'name' => 'partial',
'legalName' => 'partial',
'createdAt' => 'start',
])]
#[ApiFilter(OrderFilter::class, properties: [
'name',
'taxID',
'legalName',
'createdAt'
])]
class Insurer
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
#[Groups([
'insurer:collection:get',
'insurer:item:get',
'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:insurer',
'insurer:collection:get',
'insurer:collection:post',
'insurer:item:get',
'insurer:item:put',
'demand:collection:post',
'demand:item:get',
'demand:item:put',
'insured_insurer:collection:get',
'insured_insurer:item:get',
'insured_insurer:item:put',
'policy:collection:get',
'user:item:get',
])]
private ?string $name = 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:insurer',
'insurer:collection:get',
'insurer:collection:post',
'insurer:item:get',
'insurer: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')]
#[ApiProperty(iri: 'https://schema.org/taxID')]
#[Assert\Type('string')]
#[Groups([
'import:insurer',
'insurer:collection:get',
'insurer:collection:post',
'insurer:item:get',
'insurer:item:put',
'demand:item:get',
'policy:collection:get',
'user:item:get',
])]
private ?string $taxID = null;
/**
* A description of the item.
*
* @see https://schema.org/description
*/
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/description')]
#[Assert\Type('string')]
#[Groups([
'import:insurer',
'insurer:collection:post',
'insurer:item:get',
'insurer:item:put',
])]
private ?string $description = null;
// #[ORM\ManyToMany(targetEntity: Policy::class, mappedBy: 'insurers')]
// private $policies;
#[ORM\OneToMany(mappedBy: 'insurer', targetEntity: PolicyInsurer::class, cascade: ["persist", "remove"], orphanRemoval: true)]
private $policies;
#[ORM\ManyToMany(targetEntity: Demand::class, mappedBy: 'insurers')]
#[MaxDepth(1)]
private $demands;
#[ORM\OneToMany(mappedBy: 'insurer', targetEntity: InsuredInsurer::class, cascade: ["persist", "remove"], orphanRemoval: true)]
// #[Groups([
// 'import:insurer'
// ])]
// #[MaxDepth(1)]
private $insureds;
#[ORM\OneToMany(mappedBy: 'insurer', targetEntity: InsuredInsurerGlobal::class, cascade: ["persist", "remove"], orphanRemoval: true)]
// #[Groups([
// 'import:insurer'
// ])]
#[MaxDepth(1)]
private $insuredGlobals;
#[ORM\OneToMany(mappedBy: 'insurer', targetEntity: InsurerUser::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[Groups([
'import:insurer',
'insurer:item:get'
])]
#[MaxDepth(1)]
private $users;
#[ORM\OneToMany(mappedBy: 'insurer', targetEntity: InsurerSubmodality::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[Groups([
'import:insurer',
'insurer:item:get',
'insurer:item:put',
])]
#[MaxDepth(1)]
private $submodalities;
#[ORM\OneToMany(mappedBy: 'insurer', targetEntity: InsurerModality::class, cascade: ["persist", "remove"], orphanRemoval: true)]
#[Groups([
'import:insurer',
'insurer:item:get',
'insurer:item:put',
])]
#[MaxDepth(1)]
private $modalities;
#[ApiProperty()]
#[Groups([
'import:demand',
])]
private $insurerTaxID;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups([
'import:insurer',
'insurer:collection:get',
'insurer:collection:post',
'insurer:item:get',
'insurer:item:put',
])]
private ?float $defaultLimitValue = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:insurer',
'insurer:collection:get',
'insurer:collection:post',
'insurer:item:get',
'insurer:item:put',
])]
private ?float $defaultComissionRate = null;
#[ORM\Column(type: 'float', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/Number')]
#[Groups([
'import:insurer',
'insurer:collection:get',
'insurer:collection:post',
'insurer:item:get',
'insurer:item:put',
])]
private ?float $defaultApprovedValue = null;
#[ORM\Column(type: 'datetime', nullable: true)]
#[Groups([
'import:insurer',
'insurer:collection:get',
'insurer:collection:post',
'insurer:item:get',
'insurer:item:put',
])]
private $defaultEndTime;
public function __construct()
{
$this->policies = new ArrayCollection();
$this->demands = new ArrayCollection();
$this->insureds = new ArrayCollection();
$this->insuredGlobals = new ArrayCollection();
$this->users = new ArrayCollection();
$this->submodalities = new ArrayCollection();
$this->modalities = 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 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 setDescription(?string $description): void
{
$this->description = $description;
}
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return Collection|PolicyInsurer[]
*/
public function getPolicies(): Collection
{
return $this->policies;
}
public function addPolicy(PolicyInsurer $policy): self
{
if (!$this->policies->contains($policy)) {
$this->policies[] = $policy;
$policy->setInsurer($this);
}
return $this;
}
public function removePolicy(PolicyInsurer $policy): self
{
if ($this->policies->removeElement($policy)) {
$policy->setInsurer(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->addInsurer($this);
}
return $this;
}
public function removeDemand(Demand $demand): self
{
if ($this->demands->removeElement($demand)) {
$demand->removeInsurer($this);
}
return $this;
}
/**
* @return Collection|InsuredInsurer[]
*/
public function getInsureds(): Collection
{
return $this->insureds;
}
public function addInsured(InsuredInsurer $insured): self
{
if (!$this->insureds->contains($insured)) {
$this->insureds[] = $insured;
$insured->setInsurer($this);
}
return $this;
}
public function removeInsured(InsuredInsurer $insured): self
{
if ($this->insureds->removeElement($insured)) {
// set the owning side to null (unless already changed)
if ($insured->getInsurer() === $this) {
$insured->setInsurer(null);
}
}
return $this;
}
/**
* @return Collection|InsuredInsurerGlobal[]
*/
public function getInsuredGlobals(): Collection
{
return $this->insuredGlobals;
}
public function addInsuredGlobal(InsuredInsurerGlobal $insuredGlobal): self
{
if (!$this->insuredGlobals->contains($insuredGlobal)) {
$this->insuredGlobals[] = $insuredGlobal;
$insuredGlobal->setInsurer($this);
}
return $this;
}
public function removeInsuredGlobal(InsuredInsurerGlobal $insuredGlobal): self
{
if ($this->insuredGlobals->removeElement($insuredGlobal)) {
// set the owning side to null (unless already changed)
if ($insuredGlobal->getInsurer() === $this) {
$insuredGlobal->setInsurer(null);
}
}
return $this;
}
/**
* @return Collection|InsurerUser[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(InsurerUser $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setInsurer($this);
}
return $this;
}
public function removeUser(InsurerUser $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getInsurer() === $this) {
$user->setInsurer(null);
}
}
return $this;
}
/**
* @return Collection|InsurerSubmodality[]
*/
public function getSubmodalities(): Collection
{
return $this->submodalities;
}
public function addSubmodality(InsurerSubmodality $submodality): self
{
if (!$this->submodalities->contains($submodality)) {
$this->submodalities[] = $submodality;
$submodality->setInsurer($this);
}
return $this;
}
public function removeSubmodality(InsurerSubmodality $submodality): self
{
if ($this->submodalities->removeElement($submodality)) {
// set the owning side to null (unless already changed)
if ($submodality->getInsurer() === $this) {
$submodality->setInsurer(null);
}
}
return $this;
}
/**
* @return Collection|InsurerModality[]
*/
public function getModalities(): Collection
{
return $this->modalities;
}
public function addModality(InsurerModality $modality): self
{
if (!$this->modalities->contains($modality)) {
$this->modalities[] = $modality;
$modality->setInsurer($this);
}
return $this;
}
public function removeModality(InsurerModality $modality): self
{
if ($this->modalities->removeElement($modality)) {
// set the owning side to null (unless already changed)
if ($modality->getInsurer() === $this) {
$modality->setInsurer(null);
}
}
return $this;
}
public function getInsurerTaxID(): ?string
{
return $this->getTaxID();
}
public function getDefaultLimitValue(): ?float
{
return $this->defaultLimitValue;
}
public function setDefaultLimitValue(?float $defaultLimitValue): self
{
$this->defaultLimitValue = $defaultLimitValue;
return $this;
}
public function getDefaultComissionRate(): ?float
{
return $this->defaultComissionRate;
}
public function setDefaultComissionRate(?float $defaultComissionRate): self
{
$this->defaultComissionRate = $defaultComissionRate;
return $this;
}
public function getDefaultApprovedValue(): ?float
{
return $this->defaultApprovedValue;
}
public function setDefaultApprovedValue(?float $defaultApprovedValue): self
{
$this->defaultApprovedValue = $defaultApprovedValue;
return $this;
}
public function getDefaultEndTime(): ?\DateTimeInterface
{
return $this->defaultEndTime;
}
public function setDefaultEndTime(?\DateTimeInterface $defaultEndTime): self
{
$this->defaultEndTime = $defaultEndTime;
return $this;
}
}