<?php
namespace App\Entity\BaseSite\Plan;
use App\Entity\BaseEntity;
use App\Entity\Shop\Shop\Shop;
use App\Repository\BaseSite\Plan\PlanRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: PlanRepository::class)]
class Plan extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $days = null;
#[ORM\Column]
private ?bool $isSystematic = null;
#[ORM\OneToMany(mappedBy: 'currentPlan', targetEntity: Shop::class)]
private Collection $shops;
#[ORM\OneToMany(mappedBy: 'plan', targetEntity: PlanFeature::class)]
private Collection $planFeatures;
#[ORM\Column]
private ?bool $isTrial = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $price = null;
#[ORM\OneToMany(mappedBy: 'plan', targetEntity: AddOn::class)]
private Collection $addOns;
#[ORM\Column(nullable: true)]
private ?int $freeIrDomain = null;
public function __construct()
{
parent::__construct();
$this->shops = new ArrayCollection();
$this->planFeatures = new ArrayCollection();
$this->addOns = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getDays(): ?string
{
return $this->days;
}
public function setDays(string $days): static
{
$this->days = $days;
return $this;
}
public function isIsSystematic(): ?bool
{
return $this->isSystematic;
}
public function setIsSystematic(bool $isSystematic): static
{
$this->isSystematic = $isSystematic;
return $this;
}
/**
* @return Collection<int, Shop>
*/
public function getShops(): Collection
{
return $this->shops;
}
public function addShop(Shop $shop): static
{
if (!$this->shops->contains($shop)) {
$this->shops->add($shop);
$shop->setCurrentPlan($this);
}
return $this;
}
public function removeShop(Shop $shop): static
{
if ($this->shops->removeElement($shop)) {
// set the owning side to null (unless already changed)
if ($shop->getCurrentPlan() === $this) {
$shop->setCurrentPlan(null);
}
}
return $this;
}
/**
* @return Collection<int, PlanFeature>
*/
public function getPlanFeatures(): Collection
{
return $this->planFeatures;
}
public function addPlanFeature(PlanFeature $planFeature): static
{
if (!$this->planFeatures->contains($planFeature)) {
$this->planFeatures->add($planFeature);
$planFeature->setPlan($this);
}
return $this;
}
public function removePlanFeature(PlanFeature $planFeature): static
{
if ($this->planFeatures->removeElement($planFeature)) {
// set the owning side to null (unless already changed)
if ($planFeature->getPlan() === $this) {
$planFeature->setPlan(null);
}
}
return $this;
}
public function isIsTrial(): ?bool
{
return $this->isTrial;
}
public function setIsTrial(bool $isTrial): static
{
$this->isTrial = $isTrial;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): static
{
$this->price = $price;
return $this;
}
/**
* @return Collection<int, AddOn>
*/
public function getAddOns(): Collection
{
return $this->addOns;
}
public function addAddOn(AddOn $addOn): static
{
if (!$this->addOns->contains($addOn)) {
$this->addOns->add($addOn);
$addOn->setPlan($this);
}
return $this;
}
public function removeAddOn(AddOn $addOn): static
{
if ($this->addOns->removeElement($addOn)) {
// set the owning side to null (unless already changed)
if ($addOn->getPlan() === $this) {
$addOn->setPlan(null);
}
}
return $this;
}
public function hasFeature(string $featureKey): bool
{
foreach ($this->planFeatures as $planFeature) {
$feature = $planFeature->getFeature();
if ($feature && $feature->getFeatureKey() === $featureKey) {
return true;
}
}
return false;
}
public function getFeatureValue(string $featureKey): ?string
{
foreach ($this->planFeatures as $planFeature) {
$feature = $planFeature->getFeature();
if ($feature && $feature->getFeatureKey() === $featureKey) {
return $planFeature->getValue();
}
}
return null;
}
public function getFreeIrDomain(): ?int
{
return $this->freeIrDomain;
}
public function setFreeIrDomain(?int $freeIrDomain): static
{
$this->freeIrDomain = $freeIrDomain;
return $this;
}
}