<?php

declare(strict_types=1);

namespace App\Entity\Acteurs;

use App\Entity\Properties\Properties;
use App\Repository\Acteurs\ProprietairesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Entity(repositoryClass=ProprietairesRepository::class)
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
 */
class Proprietaires extends Acteurs
{
    public const PROPRIETAIRE_ADD_SUCCESSFULLY = 'PROPRIETAIRE_ADD_SUCCESSFULLY';
    public const PROPRIETAIRE_INVALID_FORM = 'PROPRIETAIRE_INVALID_FORM';
    protected const PROPRIETAIRE = 'PROPRIETAIRE';

    /**
     * @ORM\OneToMany(targetEntity=Properties::class, mappedBy="proprietaires", cascade={"remove"})
     */
    private Collection $properties;

    /**
     * @ORM\Column(type="integer", nullable=true, options={"default": null})
     */
    private ?int $companyId = null;

    /**
     * @ORM\Column(type="float", nullable=true)
     */
    private ?float $commission = null;



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

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

    public function getCompanyId(): ?int
    {
        return $this->companyId;
    }

    public function setCompanyId(?int $companyId): self
    {
        $this->companyId = $companyId;
        return $this;
    }

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

    public function getCommission(): ?float
    {
        return $this->commission;
    }
    public function setCommission(?float $commission): self
    {
        $this->commission = $commission;
        return $this;
    }

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

    public function addProperty(Properties $property): self
    {
        if (!$this->properties->contains($property)) {
            $this->properties[] = $property;
            $property->setProprietaires($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->getProprietaires() === $this) {
                $property->setProprietaires(null);
            }
        }

        return $this;
    }
}
