<?php
namespace App\Entity\Telegram\AgentPublicBot;
use App\Entity\BaseEntity;
use App\Entity\VPN\Service\Plan;
use App\Repository\Telegram\AgentPublicBot\BotPlanRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: BotPlanRepository::class)]
class BotPlan extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id = null;
#[ORM\ManyToOne(inversedBy: 'botPlans')]
#[ORM\JoinColumn(nullable: false)]
private ?Bot $bot = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $price = null;
#[ORM\ManyToOne(inversedBy: 'botPlans')]
private ?Plan $plan = null;
public function getId(): ?string
{
return $this->id;
}
public function getBot(): ?Bot
{
return $this->bot;
}
public function setBot(?Bot $bot): static
{
$this->bot = $bot;
return $this;
}
public function getV2rayMultiPlan(): ?V2rayMultiPlan
{
return $this->v2rayMultiPlan;
}
public function setV2rayMultiPlan(?V2rayMultiPlan $v2rayMultiPlan): static
{
$this->v2rayMultiPlan = $v2rayMultiPlan;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): static
{
$this->price = $price;
return $this;
}
public function toTelegramStringV2rayMulti(Bot $bot)
{
if ($this->getVipPlan() !== null){
if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
$title =
'زمان : '.
$this->getVipPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getVipPlan()->getSize()).' '.
'قیمت : '.
number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100 ) ) . ' تومان' .
" پس از {$bot->getOffPercent()} درصد تخفیف "
;
}else{
$title =
'زمان : '.
$this->getVipPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getVipPlan()->getSize()).' '.
'قیمت : '.
number_format($this->getPrice()) . ' تومان';
}
}
if ($this->getV2rayMultiPlan() !== null){
if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
$title =
'زمان : '.
$this->getV2rayMultiPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getV2rayMultiPlan()->getSize()).' '.
'قیمت : '.
number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100 ) ) . ' تومان' .
" پس از {$bot->getOffPercent()} درصد تخفیف "
;
}else{
$title =
'زمان : '.
$this->getV2rayMultiPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getV2rayMultiPlan()->getSize()).' '.
'قیمت : '.
number_format($this->getPrice()) . ' تومان';
}
}
if ($this->getCiscoPlan() !== null){
if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
$title =
'زمان : '.
$this->getCiscoPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getCiscoPlan()->getSize()).' '.
'قیمت : '.
number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100 ) ) . ' تومان' .
" پس از {$bot->getOffPercent()} درصد تخفیف "
;
}else{
$title =
'زمان : '.
$this->getCiscoPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getCiscoPlan()->getSize()).' '.
'قیمت : '.
number_format($this->getPrice()) . ' تومان';
}
}
if ($this->getOpenPlan() !== null){
if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
$title =
'زمان : '.
$this->getOpenPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getOpenPlan()->getSize()).' '.
'کاربر : '.
$this->getOpenPlan()->getUser().' '.
'قیمت : '.
number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100 ) ) . ' تومان' .
" پس از {$bot->getOffPercent()} درصد تخفیف "
;
}else{
$title =
'زمان : '.
$this->getOpenPlan()->getDays().' روز '.
'حجم : '.
$this->formatSizeUnits( $this->getOpenPlan()->getSize()).' '.
'کاربر : '.
$this->getOpenPlan()->getUser().' '.
'قیمت : '.
number_format($this->getPrice()) . ' تومان';
}
}
return $title;
}
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 getPlan(): ?Plan
{
return $this->plan;
}
public function setPlan(?Plan $plan): static
{
$this->plan = $plan;
return $this;
}
}