<?php

declare(strict_types=1);

namespace App\Entity\Acteurs;

use App\Entity\Quittances\Quittances;
use App\Entity\Properties\Properties;
use App\Repository\Acteurs\LocatairesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass=LocatairesRepository::class)
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
 */
class Locataires extends Acteurs
{
    public const LOCATAIRE_ADD_SUCCESSFULLY = 'LOCATAIRE_ADD_SUCCESSFULLY';
    public const LOCATAIRE_INVALID_FORM = 'LOCATAIRE_INVALID_FORM';
    public const TYPE = [
        0 => 'Particulier',
        1 => 'Entreprise'
    ];

    /**
     * @var int
     * @ORM\Column(type="integer", length=1, options={"default": 0})
     * @Assert\NotBlank(message="Veuillez sélectionner un type de locataire svp!")
     */
    protected int $type_locataire = 0;

    /**
     * @var string|null
     * @ORM\Column(type="string", length=50, nullable=true)
     */
    protected ?string $fonction = null;

    /**
     * @var string|null
     * @ORM\Column(type="string", length=30, nullable=true)
     */
    private ?string $raison_sociale = null;

    /**
     * @var string|null
     * @ORM\Column(type="string", length=30, nullable=true)
     */
    private ?string $forme_juridique = null;

    /**
     * SIREN
     * @var string|null
     * @ORM\Column(type="string", length=30, nullable=true)
     */
    private ?string $numero_siren = null;

    /**
     * RCS
     * @var string|null
     * @ORM\Column(type="string", length=30, nullable=true)
     */
    private ?string $numero_registre_commerce = null;

    /**
     * @ORM\OneToMany(targetEntity=Properties::class, mappedBy="locataires")
     * @ORM\JoinColumn(nullable=false,onDelete="SET NULL")
     */
    private Collection $properties;

    /**
     * @ORM\OneToMany(targetEntity=Quittances::class, mappedBy="locataires", cascade={"remove"})
     */
    private Collection $quittances;

    /**
     * @var bool|null
     * @ORM\Column(type="boolean", nullable=true, options={"default": false})
     */
    private ?bool $is_out = false;

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

    /**
     * @return string|null
     */
    public function getFonction(): ?string
    {
        return $this->fonction;
    }

    /**
     * @param string|null $fonction
     * @return Locataires
     */
    public function setFonction(?string $fonction): Locataires
    {
        $this->fonction = $fonction;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getRaisonSociale(): ?string
    {
        return $this->raison_sociale;
    }

    /**
     * @param string|null $raison_sociale
     * @return Locataires
     */
    public function setRaisonSociale(?string $raison_sociale): Locataires
    {
        $this->raison_sociale = $raison_sociale;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getFormeJuridique(): ?string
    {
        return $this->forme_juridique;
    }

    /**
     * @param string|null $forme_juridique
     * @return Locataires
     */
    public function setFormeJuridique(?string $forme_juridique): Locataires
    {
        $this->forme_juridique = $forme_juridique;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getNumeroSiren(): ?string
    {
        return $this->numero_siren;
    }

    /**
     * @param string|null $numero_siren
     * @return Locataires
     */
    public function setNumeroSiren(?string $numero_siren): Locataires
    {
        $this->numero_siren = $numero_siren;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getNumeroRegistreCommerce(): ?string
    {
        return $this->numero_registre_commerce;
    }

    /**
     * @param string|null $numero_registre_commerce
     * @return Locataires
     */
    public function setNumeroRegistreCommerce(?string $numero_registre_commerce): Locataires
    {
        $this->numero_registre_commerce = $numero_registre_commerce;
        return $this;
    }

    /**
     * @return string
     */
    public function __toString(): string
    {
        return $this->name;
    }

    public function isRole(): string
    {
        return self::ROLES['LOCATAIRE'];
    }

    /**
     * @return int
     */
    public function getTypeLocataire(): int
    {
        return $this->type_locataire;
    }

    /**
     * @param int $type_locataire
     * @return Locataires
     */
    public function setTypeLocataire(int $type_locataire): Locataires
    {
        $this->type_locataire = $type_locataire;
        return $this;
    }

    public function getType(): string
    {
        return self::TYPE[$this->type_locataire];
    }

    /**
     * @return Collection
     */
    public function getProperties(): Collection
    {
        return $this->properties;
    }

    public function addProperty(Properties $property): self
    {
        if (!$this->properties->contains($property)) {
            $this->properties[] = $property;
            $property->setLocataires($this);
        }

        return $this;
    }

    public function removeProperty(Properties $property): self
    {
        if ($this->properties->removeElement($property)) {
            // set the owning side to null (unless already changed)
            if ($property->getLocataires() === $this) {
                $property->setLocataires(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection
     */
    public function getQuittances(): Collection
    {
        return $this->quittances;
    }

    public function addLoyer(Quittances $quittance): self
    {
        if (!$this->quittances->contains($quittance)) {
            $this->quittances[] = $quittance;
            $quittance->setLocataires($this);
        }

        return $this;
    }

    public function removeLoyer(Quittances $quittance): self
    {
        if ($this->quittances->removeElement($quittance)) {
            // set the owning side to null (unless already changed)
            if ($quittance->getLocataires() === $this) {
                $quittance->setLocataires(null);
            }
        }

        return $this;
    }

    public function getIsOut(): ?bool
    {
        return $this->is_out;
    }

    public function setIsOut(?bool $is_out): Locataires
    {
        $this->is_out = $is_out;
        return $this;
    }
}
