<?php

namespace App\Entity;

use App\Repository\TypeEnergieRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ORM\Entity(repositoryClass=TypeEnergieRepository::class)
 * @ORM\Table(schema="sav")
 */
class TypeEnergie
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"api"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=30)
     * @Groups({"api"})
     */
    private $libelle;

    /**
     * @ORM\OneToMany(targetEntity=Energie::class, mappedBy="type_energie")
     */
    private $energies;

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

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

    public function getLibelle(): ?string
    {
        return $this->libelle;
    }

    public function setLibelle(string $libelle): self
    {
        $this->libelle = $libelle;

        return $this;
    }

    /**
     * @return Collection<int, Energie>
     */
    public function getEnergies(): Collection
    {
        return $this->energies;
    }

    public function addEnergy(Energie $energy): self
    {
        if (!$this->energies->contains($energy)) {
            $this->energies[] = $energy;
            $energy->setTypeEnergie($this);
        }

        return $this;
    }

    public function removeEnergy(Energie $energy): self
    {
        if ($this->energies->removeElement($energy)) {
            // set the owning side to null (unless already changed)
            if ($energy->getTypeEnergie() === $this) {
                $energy->setTypeEnergie(null);
            }
        }

        return $this;
    }
}
