<?php
namespace App\Entity\Server\Hetzner;
use App\Entity\BaseEntity;
use App\Repository\Server\Hetzner\DataCenterRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: DataCenterRepository::class)]
#[ORM\Table(name: '`hetzner_sell_server_datacenter`')]
class DataCenter 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 $description = null;
#[ORM\ManyToOne(inversedBy: 'dataCenters')]
#[ORM\JoinColumn(nullable: false)]
private ?Location $location = null;
#[ORM\OneToMany(mappedBy: 'datacenter', targetEntity: DataCenterSupportedServerTypes::class)]
private Collection $dataCenterSupportedServerTypes;
#[ORM\OneToMany(mappedBy: 'datacenter', targetEntity: Server::class)]
private Collection $servers;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
public function __construct()
{
parent::__construct();
$this->dataCenterSupportedServerTypes = new ArrayCollection();
$this->servers = new ArrayCollection();
}
public function __toString()
{
return $this->getLocation()->getCountry().' - '.$this->getLocation()->getCity() .' - '. $this->getName();
}
public function getId(): ?string
{
return $this->id;
}
public function getSystemId(): ?string
{
return $this->systemId;
}
public function setSystemId(?string $systemId): static
{
$this->systemId = $systemId;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getLocation(): ?Location
{
return $this->location;
}
public function setLocation(?Location $location): static
{
$this->location = $location;
return $this;
}
/**
* @return Collection<int, DataCenterSupportedServerTypes>
*/
public function getDataCenterSupportedServerTypes(): Collection
{
return $this->dataCenterSupportedServerTypes;
}
public function addDataCenterSupportedServerType(DataCenterSupportedServerTypes $dataCenterSupportedServerType): static
{
if (!$this->dataCenterSupportedServerTypes->contains($dataCenterSupportedServerType)) {
$this->dataCenterSupportedServerTypes->add($dataCenterSupportedServerType);
$dataCenterSupportedServerType->setDatacenter($this);
}
return $this;
}
public function removeDataCenterSupportedServerType(DataCenterSupportedServerTypes $dataCenterSupportedServerType): static
{
if ($this->dataCenterSupportedServerTypes->removeElement($dataCenterSupportedServerType)) {
// set the owning side to null (unless already changed)
if ($dataCenterSupportedServerType->getDatacenter() === $this) {
$dataCenterSupportedServerType->setDatacenter(null);
}
}
return $this;
}
/**
* @return Collection<int, Server>
*/
public function getServers(): Collection
{
return $this->servers;
}
public function addServer(Server $server): static
{
if (!$this->servers->contains($server)) {
$this->servers->add($server);
$server->setDatacenter($this);
}
return $this;
}
public function removeServer(Server $server): static
{
if ($this->servers->removeElement($server)) {
// set the owning side to null (unless already changed)
if ($server->getDatacenter() === $this) {
$server->setDatacenter(null);
}
}
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
}