<?php
namespace App\Containers\SettingSection\ListContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use App\Containers\SettingSection\ListContainer\Data\Repositories\InsuranceProductRepository;
use App\Containers\SettingSection\ListContainer\Entities\RiskEntity;
use App\Containers\SettingSection\ListContainer\Entities\InsuranceProductBenefitEntity;
use App\Containers\SettingSection\ListContainer\Entities\TariffInsuranceProductEntity;
use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Страховые продукты
*/
#[ApiResource(
routePrefix: '/list',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/insurance_products/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/insurance_products/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
// new Put(
// uriTemplate: '/insurance_products/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN')"
// ),
new Delete(
uriTemplate: '/insurance_products/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/insurance_products',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/insurance_products',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
shortName: 'List_InsuranceProducts'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'risks' => 'exact',
'tariffs' => 'exact',
'benefits' => 'exact',
'name' => 'partial',
'code' => 'partial',
'shortDescription' => 'partial',
'description' => 'partial'
])]
#[ApiFilter(NumericFilter::class, properties: ['id', 'sorting', 'mileage'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'sorting', 'mileage', 'priceUAH'])]
#[ApiFilter(BooleanFilter::class, properties: ['isActive', 'isUseFixedPrice', 'isInactiveHijacked'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: ['name', 'code', 'shortDescription', 'description'])]
#[ORM\Entity(repositoryClass: InsuranceProductRepository::class)]
#[ORM\Table(name: '`list_insurance_products`')]
#[ORM\Index(columns: ['code'], name: 'list_insurance_products_custom_idx')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class InsuranceProductEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Название
#[ORM\Column(type: Types::STRING, length: 255)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private string $name;
// Символьный код
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $code = null;
// Сортування
#[ORM\Column(type: Types::INTEGER, length: 10, options: ['default' => 500])]
#[Groups(['read'])]
private ?int $sorting = 500;
// Активность
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => true])]
#[Groups(['read'])]
private bool $isActive = true;
// Количество километража
#[ORM\Column(type: Types::INTEGER, length: 10, options: ['default' => 0])]
#[Groups(['read'])]
private ?int $mileage = 0;
// Использовать фиксированную стоимость
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
#[Groups(['read'])]
private bool $isUseFixedPrice = false;
// Фиксированная стоимость в ГРН
#[ORM\Column(type: Types::FLOAT, scale: 3, nullable: true)]
#[Groups(['read'])]
private ?float $priceUAH = null;
// Риски
#[ORM\JoinTable(name: 'binding_insurance_products_risks')]
#[ORM\JoinColumn(name: 'insurance_product_id', referencedColumnName: 'id', nullable: false)]
#[ORM\InverseJoinColumn(name: 'risk_id', referencedColumnName: 'id', nullable: false)]
#[ORM\ManyToMany(targetEntity: RiskEntity::class)]
#[Groups(['read'])]
private Collection $risks;
// Краткое описание
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $shortDescription = null;
// Описание
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $description = null;
// Код цвета блока
#[ORM\Column(type: Types::STRING, nullable: true)]
#[Groups(['read'])]
private ?string $codeColor = 'green';
// Неактивно для угоняемых авто
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
#[Groups(['read'])]
private bool $isInactiveHijacked = false;
// Максимальная стоимость угоняемого авто в ГРН
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $inactiveHijackedMaxCarPriceUAH = null;
// Преимущества
#[ORM\JoinTable(name: 'binding_insurance_products_benefits')]
#[ORM\JoinColumn(name: 'insurance_product_id', referencedColumnName: 'id', nullable: false)]
#[ORM\InverseJoinColumn(name: 'benefit_id', referencedColumnName: 'id', nullable: false)]
#[ORM\ManyToMany(targetEntity: InsuranceProductBenefitEntity::class)]
#[Groups(['read'])]
private ?Collection $benefits = null;
// Тарифы
#[ORM\JoinColumn(nullable: false)]
#[ORM\OneToMany(targetEntity: TariffInsuranceProductEntity::class, mappedBy: 'insuranceProduct')]
#[Groups(['read'])]
private Collection $tariffs;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $updatedAt;
/**
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
#[Gedmo\Locale]
private $locale;
public function __construct()
{
$this->risks = new ArrayCollection();
$this->benefits = new ArrayCollection();
$this->tariffs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getCode()
{
return $this->code;
}
public function setCode($code)
{
$this->code = $code;
return $this;
}
public function getSorting()
{
return $this->sorting;
}
public function setSorting($sorting)
{
$this->sorting = $sorting;
return $this;
}
public function getIsActive()
{
return $this->isActive;
}
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
public function getMileage()
{
return $this->mileage;
}
public function setMileage($mileage)
{
$this->mileage = $mileage;
return $this;
}
public function getIsUseFixedPrice()
{
return $this->isUseFixedPrice;
}
public function setIsUseFixedPrice($isUseFixedPrice)
{
$this->isUseFixedPrice = $isUseFixedPrice;
return $this;
}
public function getPriceUAH()
{
return $this->priceUAH;
}
public function setPriceUAH($price)
{
$this->priceUAH = ($price ? round($price, 3) : null);
return $this;
}
public function getRisks()
{
return $this->risks->getValues();
}
public function addRisk(RiskEntity $risk)
{
$this->risks[] = $risk;
return $this;
}
public function removeRisk(RiskEntity $risk)
{
$this->risks->removeElement($risk);
}
public function getShortDescription()
{
return $this->shortDescription;
}
public function setShortDescription($text)
{
$this->shortDescription = $text;
return $this;
}
public function getDescription()
{
return $this->description;
}
public function setDescription($text)
{
$this->description = $text;
return $this;
}
public function getCodeColor()
{
return $this->codeColor;
}
public function setCodeColor($code)
{
$this->codeColor = $code;
return $this;
}
public function getIsInactiveHijacked()
{
return $this->isInactiveHijacked;
}
public function setIsInactiveHijacked($isInactiveHijacked)
{
$this->isInactiveHijacked = $isInactiveHijacked;
return $this;
}
public function getInactiveHijackedMaxCarPriceUAH()
{
return $this->inactiveHijackedMaxCarPriceUAH;
}
public function setInactiveHijackedMaxCarPriceUAH($price)
{
$this->inactiveHijackedMaxCarPriceUAH = $price;
return $this;
}
public function getBenefits()
{
return $this->benefits->getValues();
}
public function addBenefit(InsuranceProductBenefitEntity $benefit)
{
$this->benefits[] = $benefit;
return $this;
}
public function removeBenefit(InsuranceProductBenefitEntity $benefit)
{
$this->benefits->removeElement($benefit);
}
public function getTariffs()
{
return $this->tariffs->getValues();
}
public function addTariff(TariffInsuranceProductEntity $tariff)
{
$this->tariffs[] = $tariff;
}
public function removeTariff(TariffInsuranceProductEntity $tariff)
{
$this->tariffs->removeElement($tariff);
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}