<?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\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: ['insurer', 'modality'])]
#[ApiResource(
iri: 'InsurerModality',
itemOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insurer_modality:item:get',
'enable_max_depth' => true
]
],
'put' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insurer_modality:item:put',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insurer_modality:item:put',
'enable_max_depth' => true
]
],
'delete' => [
// 'security' => "is_granted('ROLE_USER')",
]
],
collectionOperations: [
'get' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => ['insurer_modality:collection:get', 'createdAt'],
'enable_max_depth' => true
]
],
'post' => [
// 'security' => "is_granted('ROLE_USER')",
'normalization_context' => [
'groups' => 'insurer_modality:collection:post',
'enable_max_depth' => true
],
'denormalization_context' => [
'groups' => 'insurer_modality:collection:post',
'enable_max_depth' => true
]
],
]
)]
#[ApiFilter(SearchFilter::class, properties: [
'modality' => 'exact',
'insurer' => 'exact'
])]
class InsurerModality
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups([
'insurer_modality:collection:get',
'insurer_modality:item:get',
])]
private $id;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups([
'import:insurer',
'insurer_modality:collection:get',
'insurer_modality:collection:post',
'insurer_modality:item:get',
'insurer_modality:item:put',
'insurer:item:get',
'insurer:item:put',
])]
private $limitValue;
#[ORM\ManyToOne(targetEntity: Insurer::class, inversedBy: 'modalities')]
#[Groups([
'insurer_modality:collection:get',
'insurer_modality:collection:post',
'insurer_modality:item:get',
'insurer_modality:item:put',
])]
#[MaxDepth(1)]
private $insurer;
#[ORM\ManyToOne(targetEntity: Modality::class, inversedBy: 'insurers')]
#[Groups([
'insurer_modality:collection:get',
'insurer_modality:collection:post',
'insurer_modality:item:get',
'insurer_modality:item:put',
'insurer:item:get',
])]
#[MaxDepth(1)]
private $modality;
#[ORM\Column(type: 'boolean')]
#[Assert\Type('boolean')]
#[Groups([
'import:insurer',
'insurer_modality:collection:get',
'insurer_modality:collection:post',
'insurer_modality:item:get',
'insurer_modality:item:put',
'insurer:item:get',
'insurer:item:put',
])]
private bool $isSelected = false;
#[ApiProperty()]
#[Groups([
'import:insurer',
'insurer_modality:collection:get',
'insurer:item:get',
])]
private $modalityName;
public function getId(): ?int
{
return $this->id;
}
public function getLimitValue(): ?float
{
return $this->limitValue;
}
public function setLimitValue(?float $limitValue): self
{
$this->limitValue = $limitValue;
return $this;
}
public function getInsurer(): ?Insurer
{
return $this->insurer;
}
public function setInsurer(?Insurer $insurer): self
{
$this->insurer = $insurer;
return $this;
}
public function getModality(): ?Modality
{
return $this->modality;
}
public function setModality(?Modality $modality): self
{
$this->modality = $modality;
return $this;
}
public function setIsSelected($isSelected): self
{
$this->isSelected = $isSelected;
return $this;
}
public function getIsSelected(): ?bool
{
return $this->isSelected;
}
public function getModalityName(): ?string
{
return $this->getModality()->getName();
}
}