<?php
namespace App\Entity\Server\Hetzner;
use App\Entity\BaseEntity;
use App\Entity\Generic\User;
use App\Repository\Server\Hetzner\ServerRepository;
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: ServerRepository::class)]
#[ORM\Table(name: '`hetzner_sell_server_server`')]
class Server extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private $id;
#[ORM\Column(length: 255, nullable: true)]
private ?string $systemId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $status = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $outgoingTraffic = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $ingoingTraffic = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $includedTraffic = null;
#[ORM\OneToMany(mappedBy: 'server', targetEntity: Ip::class)]
private Collection $ips;
#[ORM\ManyToOne(inversedBy: 'hetznerServers')]
#[ORM\JoinColumn(nullable: false)]
private ?User $owner = null;
#[ORM\ManyToOne(inversedBy: 'servers')]
#[ORM\JoinColumn(nullable: false)]
private ?ServerType $serverType = null;
#[ORM\ManyToOne(inversedBy: 'servers')]
#[ORM\JoinColumn(nullable: false)]
private ?DataCenter $datacenter = null;
#[ORM\ManyToOne(inversedBy: 'servers')]
#[ORM\JoinColumn(nullable: false)]
private ?Image $image = null;
#[ORM\Column(length: 255)]
private ?string $rootPassword = null;
#[ORM\Column]
private ?bool $rescueEnabled = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $payMethod = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $paidUntil = null;
#[ORM\Column(nullable: true)]
private ?bool $isPowerOn = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $lastRebuild = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $analytics = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $actions = null;
#[ORM\Column]
private ?bool $isSuspended = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $suspendType = null;
public function __construct()
{
parent::__construct();
$this->setIsSuspended(false);
$this->ips = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getNiceIps()
{
$string = '';
foreach ($this->getIps() as $ip) {
$string = $string . $ip->getIp() . '<br>';
}
return $string;
}
public function getNiceName()
{
$string = '';
$string = $string . $this->getName() . '<br>';
$string = $string . $this->getSystemId().'#' ;
return $string;
}
public function getServerStatusString()
{
switch ($this->getStatus()){
case 'initializing':
return '<span class="text-danger">در حال ساخت</span>';
break;
case 'running':
return '<span class="text-success">روشن</span>';
break;
case 'off':
return '<span class="text-danger">خاموش</span>';
case 'starting':
return '<span class="text-warning">در حال روشن شدن</span>';
break;
default:
return '<span class="text-danger">'.$this->getStatus().'</span>';
break;
}
}
public function getSystemId(): ?string
{
return $this->systemId;
}
public function setSystemId(?string $systemId): static
{
$this->systemId = $systemId;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): static
{
$this->status = $status;
return $this;
}
public function getOutgoingTraffic(): ?string
{
return $this->outgoingTraffic;
}
public function setOutgoingTraffic(?string $outgoingTraffic): static
{
$this->outgoingTraffic = $outgoingTraffic;
return $this;
}
public function getIngoingTraffic(): ?string
{
return $this->ingoingTraffic;
}
public function setIngoingTraffic(?string $ingoingTraffic): static
{
$this->ingoingTraffic = $ingoingTraffic;
return $this;
}
public function getIncludedTraffic(): ?string
{
return $this->includedTraffic;
}
public function setIncludedTraffic(?string $includedTraffic): static
{
$this->includedTraffic = $includedTraffic;
return $this;
}
/**
* @return Collection<int, Ip>
*/
public function getIps(): Collection
{
return $this->ips;
}
public function addIp(Ip $ip): static
{
if (!$this->ips->contains($ip)) {
$this->ips->add($ip);
$ip->setServer($this);
}
return $this;
}
public function removeIp(Ip $ip): static
{
if ($this->ips->removeElement($ip)) {
// set the owning side to null (unless already changed)
if ($ip->getServer() === $this) {
$ip->setServer(null);
}
}
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(?User $owner): static
{
$this->owner = $owner;
return $this;
}
public function getServerType(): ?ServerType
{
return $this->serverType;
}
public function setServerType(?ServerType $serverType): static
{
$this->serverType = $serverType;
return $this;
}
public function getDatacenter(): ?DataCenter
{
return $this->datacenter;
}
public function setDatacenter(?DataCenter $datacenter): static
{
$this->datacenter = $datacenter;
return $this;
}
public function getImage(): ?Image
{
return $this->image;
}
public function setImage(?Image $image): static
{
$this->image = $image;
return $this;
}
public function getRootPassword(): ?string
{
return $this->rootPassword;
}
public function setRootPassword(string $rootPassword): static
{
$this->rootPassword = $rootPassword;
return $this;
}
public function isRescueEnabled(): ?bool
{
return $this->rescueEnabled;
}
public function setRescueEnabled(bool $rescueEnabled): static
{
$this->rescueEnabled = $rescueEnabled;
return $this;
}
public function getPayMethod(): ?string
{
return $this->payMethod;
}
public function setPayMethod(?string $payMethod): static
{
$this->payMethod = $payMethod;
return $this;
}
public function getPaidUntil(): ?\DateTimeInterface
{
return $this->paidUntil;
}
public function setPaidUntil(?\DateTimeInterface $paidUntil): static
{
$this->paidUntil = $paidUntil;
return $this;
}
public function isIsPowerOn(): ?bool
{
return $this->isPowerOn;
}
public function setIsPowerOn(?bool $isPowerOn): static
{
$this->isPowerOn = $isPowerOn;
return $this;
}
public function getLastRebuild(): ?\DateTimeInterface
{
return $this->lastRebuild;
}
public function setLastRebuild(?\DateTimeInterface $lastRebuild): static
{
$this->lastRebuild = $lastRebuild;
return $this;
}
public function getAnalytics(): ?string
{
return $this->analytics;
}
public function setAnalytics(?string $analytics): static
{
$this->analytics = $analytics;
return $this;
}
public function getActions(): ?string
{
return $this->actions;
}
public function setActions(?string $actions): static
{
$this->actions = $actions;
return $this;
}
public function isIsSuspended(): ?bool
{
return $this->isSuspended;
}
public function setIsSuspended(bool $isSuspended): static
{
$this->isSuspended = $isSuspended;
return $this;
}
public function getSuspendType(): ?string
{
return $this->suspendType;
}
public function setSuspendType(?string $suspendType): static
{
$this->suspendType = $suspendType;
return $this;
}
}