<?php

namespace App\Entity;

use App\Repository\SubnetRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: SubnetRepository::class)]
class Subnet extends AbstractEntity
{
    use NameableTrait;
    use SynchronizedTrait;

    #[ORM\Column(length: 255)]
    private ?string $netmask = null;

    #[ORM\Column(length: 255)]
    private ?string $ipAddress = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $nextServer = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $bootFileName = null;

    /**
     * @var Collection<int, OrganizationalUnit>
     */
    #[ORM\OneToMany(mappedBy: 'subnet', targetEntity: OrganizationalUnit::class)]
    private Collection $organizationalUnits;

    /**
     * @var Collection<int, Client>
     */
    #[ORM\OneToMany(mappedBy: 'subnet', targetEntity: Client::class)]
    private Collection $clients;

    #[ORM\Column(nullable: true)]
    private ?int $serverId = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $router = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $dns = null;

    public function __construct()
    {
        parent::__construct();
        $this->organizationalUnits = new ArrayCollection();
        $this->clients = new ArrayCollection();
    }

    public function getNetmask(): ?string
    {
        return $this->netmask;
    }

    public function setNetmask(string $netmask): static
    {
        $this->netmask = $netmask;

        return $this;
    }

    public function getIpAddress(): ?string
    {
        return $this->ipAddress;
    }

    public function setIpAddress(string $ipAddress): static
    {
        $this->ipAddress = $ipAddress;

        return $this;
    }

    public function getNextServer(): ?string
    {
        return $this->nextServer;
    }

    public function setNextServer(?string $nextServer): static
    {
        $this->nextServer = $nextServer;

        return $this;
    }

    public function getBootFileName(): ?string
    {
        return $this->bootFileName;
    }

    public function setBootFileName(?string $bootFileName): static
    {
        $this->bootFileName = $bootFileName;

        return $this;
    }

    /**
     * @return Collection<int, OrganizationalUnit>
     */
    public function getOrganizationalUnits(): Collection
    {
        return $this->organizationalUnits;
    }

    public function setOrganizationalUnits(array $organizationalUnits): static
    {
        $this->organizationalUnits->clear();

        foreach ($organizationalUnits as $organizationalUnit){
            $this->addOrganizationalUnit($organizationalUnit);
        }

        return $this;
    }

    public function addOrganizationalUnit(OrganizationalUnit $organizationalUnit): static
    {
        if (!$this->organizationalUnits->contains($organizationalUnit)) {
            $this->organizationalUnits->add($organizationalUnit);
            $organizationalUnit->setSubnet($this);
        }

        return $this;
    }

    public function removeOrganizationalUnit(OrganizationalUnit $organizationalUnit): static
    {
        if ($this->organizationalUnits->removeElement($organizationalUnit)) {
            // set the owning side to null (unless already changed)
            if ($organizationalUnit->getSubnet() === $this) {
                $organizationalUnit->setSubnet(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Client>
     */
    public function getClients(): Collection
    {
        return $this->clients;
    }

    public function setClients(array $clients): static
    {
        $this->clients->clear();

        foreach ($clients as $client){
            $this->addClient($client);
        }

        return $this;
    }

    public function addClient(Client $client): static
    {
        if (!$this->clients->contains($client)) {
            $this->clients->add($client);
            $client->setSubnet($this);
        }

        return $this;
    }

    public function removeClient(Client $client): static
    {
        if ($this->clients->removeElement($client)) {
            if ($client->getSubnet() === $this) {
                $client->setSubnet(null);
            }
        }

        return $this;
    }

    public function getServerId(): ?int
    {
        return $this->serverId;
    }

    public function setServerId(?int $serverId): static
    {
        $this->serverId = $serverId;

        return $this;
    }

    public function getRouter(): ?string
    {
        return $this->router;
    }

    public function setRouter(?string $router): static
    {
        $this->router = $router;

        return $this;
    }

    public function getDns(): ?string
    {
        return $this->dns;
    }

    public function setDns(?string $dns): static
    {
        $this->dns = $dns;

        return $this;
    }
}
