<?php

namespace App\Entity;

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

/**
 * @ORM\Entity(repositoryClass=TypeClientRepository::class)
 * @ORM\Table(schema="sav")
 */
class TypeClient
{
    const ID_TYPE_PARTICULIER = 1;
    const ID_TYPE_PRO = 2;
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"api", "planning"})
     */
    private $id;

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

    /**
     * @ORM\OneToMany(targetEntity=Client::class, mappedBy="type_client")
     * @Ignore()
     */
    private $clients;

    public function __construct()
    {
        $this->clients = 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, Client>
     */
    public function getClients(): Collection
    {
        return $this->clients;
    }

    public function addClient(Client $client): self
    {
        if (!$this->clients->contains($client)) {
            $this->clients[] = $client;
            $client->setTypeClient($this);
        }

        return $this;
    }

    public function removeClient(Client $client): self
    {
        if ($this->clients->removeElement($client)) {
            // set the owning side to null (unless already changed)
            if ($client->getTypeClient() === $this) {
                $client->setTypeClient(null);
            }
        }

        return $this;
    }

    public function isParticulier() {
        return $this->id == self::ID_TYPE_PARTICULIER;
    }
}
