<?php

namespace App\Entity;

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

#[ORM\Entity(repositoryClass: OperativeSystemRepository::class)]
class OperativeSystem extends AbstractEntity
{
    use NameableTrait;

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

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

    /**
     * @return Collection<int, Partition>
     */
    public function getPartitions(): Collection
    {
        return $this->partitions;
    }

    public function addPartition(Partition $partition): static
    {
        if (!$this->partitions->contains($partition)) {
            $this->partitions->add($partition);
            $partition->setOperativeSystem($this);
        }

        return $this;
    }

    public function removePartition(Partition $partition): static
    {
        if ($this->partitions->removeElement($partition)) {
            // set the owning side to null (unless already changed)
            if ($partition->getOperativeSystem() === $this) {
                $partition->setOperativeSystem(null);
            }
        }

        return $this;
    }
}
