<?php
namespace App\Entity\VPN\Service;
use App\Entity\BaseEntity;
use App\Entity\Country;
use App\Entity\Telegram\AgentPublicBot\BotPlan;
use App\Repository\VPN\Service\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 = null;
#[ORM\Column]
private ?int $days = null;
#[ORM\Column(length: 255)]
private ?string $serviceType = null;
#[ORM\Column(length: 255)]
private ?string $protocol = null;
#[ORM\Column(length: 255)]
private ?string $size = null;
#[ORM\Column]
private ?int $users = null;
#[ORM\Column(length: 255)]
private ?string $country = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $price = null;
/**
* @var Collection<int, Service>
*/
#[ORM\OneToMany(targetEntity: Service::class, mappedBy: 'plan')]
private Collection $services;
#[ORM\Column]
private ?bool $hasV2ray = null;
#[ORM\Column]
private ?bool $hasCisco = null;
#[ORM\Column]
private ?bool $hasOpenVpn = null;
#[ORM\OneToMany(mappedBy: 'plan', targetEntity: BotPlan::class)]
private Collection $botPlans;
public function __construct()
{
parent::__construct();
$this->services = new ArrayCollection();
$this->botPlans = new ArrayCollection();
}
public function formatSizeUnits($bytes): string
{
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . ' MB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . ' KB';
} elseif ($bytes > 1) {
$bytes = $bytes . ' bytes';
} elseif ($bytes == 1) {
$bytes = $bytes . ' byte';
} else {
$bytes = '0 bytes';
}
return $bytes;
}
public function __toString()
{
$ltr = "\u{200E}"; // کاراکتر جهتدهی چپبهراست (LTR)
$parts = [];
if ($this->hasOpenVpn) {
$parts[] = $ltr . 'OpenVPN'; // اعمال جهت LTR برای کلمات انگلیسی
}
if ($this->hasCisco) {
$parts[] = $ltr . 'Cisco';
}
if ($this->hasV2ray) {
$parts[] = $ltr . 'V2ray';
}
if ($this->serviceType == 'unlimited') {
$parts[] = 'نامحدود';
}
if ($this->serviceType == 'sized') {
$parts[] = 'محدود حجمی';
}
if ($this->getUsers() !== 0) {
$parts[] = $this->getUsers() . ' کاربره';
}
if ($this->getDays() !== 0) {
$parts[] = $this->getDays() . ' روزه';
}
if ($this->serviceType == 'sized') {
$size = $this->getSize();
$sizeUnit = 'گیگ';
$parts[] = $this->formatSizeUnits($size );
}
return implode(' ', $parts);
}
public function getId(): ?string
{
return $this->id;
}
public function getDays(): ?int
{
return $this->days;
}
public function setDays(int $days): static
{
$this->days = $days;
return $this;
}
public function getServiceType(): ?string
{
return $this->serviceType;
}
public function setServiceType(string $serviceType): static
{
$this->serviceType = $serviceType;
return $this;
}
public function getProtocol(): ?string
{
return $this->protocol;
}
public function setProtocol(string $protocol): static
{
$this->protocol = $protocol;
return $this;
}
public function getSize(): ?int
{
return $this->size;
}
public function setSize(int $size): static
{
$this->size = $size;
return $this;
}
public function getUsers(): ?int
{
return $this->users;
}
public function setUsers(int $users): static
{
$this->users = $users;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): static
{
$this->country = $country;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): static
{
$this->price = $price;
return $this;
}
/**
* @return Collection<int, Service>
*/
public function getServices(): Collection
{
return $this->services;
}
public function addService(Service $service): static
{
if (!$this->services->contains($service)) {
$this->services->add($service);
$service->setPlan($this);
}
return $this;
}
public function removeService(Service $service): static
{
if ($this->services->removeElement($service)) {
// set the owning side to null (unless already changed)
if ($service->getPlan() === $this) {
$service->setPlan(null);
}
}
return $this;
}
public function hasV2ray(): ?bool
{
return $this->hasV2ray;
}
public function setHasV2ray(bool $hasV2ray): static
{
$this->hasV2ray = $hasV2ray;
return $this;
}
public function hasCisco(): ?bool
{
return $this->hasCisco;
}
public function setHasCisco(bool $hasCisco): static
{
$this->hasCisco = $hasCisco;
return $this;
}
public function hasOpenVpn(): ?bool
{
return $this->hasOpenVpn;
}
public function setHasOpenVpn(bool $hasOpenVpn): static
{
$this->hasOpenVpn = $hasOpenVpn;
return $this;
}
/**
* @return Collection<int, BotPlan>
*/
public function getBotPlans(): Collection
{
return $this->botPlans;
}
public function addBotPlan(BotPlan $botPlan): static
{
if (!$this->botPlans->contains($botPlan)) {
$this->botPlans->add($botPlan);
$botPlan->setPlan($this);
}
return $this;
}
public function removeBotPlan(BotPlan $botPlan): static
{
if ($this->botPlans->removeElement($botPlan)) {
// set the owning side to null (unless already changed)
if ($botPlan->getPlan() === $this) {
$botPlan->setPlan(null);
}
}
return $this;
}
}