<?php

namespace App\Entity;

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

/**
 * @ORM\Entity(repositoryClass=SubgroupRepository::class)
 */
class Subgroup
{
    public function __toString()
    {
        return $this->name;
    }
    public const NUM_ITEMS = 10;
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity=Group::class, inversedBy="subgroups")
     * @ORM\JoinColumn(nullable=false)
     */
    private $groups;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $remarks;

    /**
     * @ORM\OneToMany(targetEntity=Assetname::class, mappedBy="subgroup")
     */
    private $assetnames;

    /**
     * @ORM\OneToMany(targetEntity=Assetregister::class, mappedBy="subgroup")
     */
    private $assetregisters;

    public function __construct()
    {
        $this->assetnames = new ArrayCollection();
        $this->assetregisters = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getGroups(): ?Group
    {
        return $this->groups;
    }

    public function setGroups(?Group $groups): self
    {
        $this->groups = $groups;

        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getRemarks(): ?string
    {
        return $this->remarks;
    }

    public function setRemarks(?string $remarks): self
    {
        $this->remarks = $remarks;

        return $this;
    }

    /**
     * @return Collection|Assetname[]
     */
    public function getAssetnames(): Collection
    {
        return $this->assetnames;
    }

    public function addAssetname(Assetname $assetname): self
    {
        if (!$this->assetnames->contains($assetname)) {
            $this->assetnames[] = $assetname;
            $assetname->setSubgroup($this);
        }

        return $this;
    }

    public function removeAssetname(Assetname $assetname): self
    {
        if ($this->assetnames->removeElement($assetname)) {
            // set the owning side to null (unless already changed)
            if ($assetname->getSubgroup() === $this) {
                $assetname->setSubgroup(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Assetregister[]
     */
    public function getAssetregisters(): Collection
    {
        return $this->assetregisters;
    }

    public function addAssetregister(Assetregister $assetregister): self
    {
        if (!$this->assetregisters->contains($assetregister)) {
            $this->assetregisters[] = $assetregister;
            $assetregister->setSubgroup($this);
        }

        return $this;
    }

    public function removeAssetregister(Assetregister $assetregister): self
    {
        if ($this->assetregisters->removeElement($assetregister)) {
            // set the owning side to null (unless already changed)
            if ($assetregister->getSubgroup() === $this) {
                $assetregister->setSubgroup(null);
            }
        }

        return $this;
    }
}
