<?php

namespace App\Entity;

use App\Repository\EtatCivilRepository;
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=EtatCivilRepository::class)
 * @ORM\Table(schema="sav")
 */
class EtatCivil
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"api", "map", "planning"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=25, nullable=true)
     * @Groups({"api", "map", "planning"})
     */
    private $libelle_court;

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

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

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

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

    public function setId(?int $id): self
    {
        $this->id = $id;

        return $this;
    }

    public function getLibelleCourt(): ?string
    {
        return $this->libelle_court;
    }

    public function setLibelleCourt(?string $libelle_court): self
    {
        $this->libelle_court = $libelle_court;

        return $this;
    }

    public function getLibelleLong(): ?string
    {
        return $this->libelle_long;
    }

    public function setLibelleLong(?string $libelle_long): self
    {
        $this->libelle_long = $libelle_long;

        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->setEtatCivil($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->getEtatCivil() === $this) {
                $client->setEtatCivil(null);
            }
        }

        return $this;
    }

    public function __toString() {
        return $this->getLibelleCourt();
    }
}
