<?php
declare (strict_types=1);

namespace App\Entity\Billing;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Organization\Organization;
use App\Repository\Billing\BillingSettingRepository;
//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure;

#[ApiResource(
    operations: [
        new Get()
    ]
)]
//#[Auditable]
#[ORM\Entity(repositoryClass: BillingSettingRepository::class)]
class BillingSetting
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\OneToOne(inversedBy: 'billingSetting')]
    #[ORM\JoinColumn(nullable: false)]
    private Organization $organization;

    #[ORM\OneToMany(mappedBy: 'billingSetting', targetEntity: ResidenceArea::class, cascade: ['persist'], orphanRemoval: true)]
    private Collection $residenceAreas;

    #[ORM\Column(options: ['default' => false])]
    private bool $applyVat = false;

    #[ORM\OneToMany(mappedBy: 'billingSetting', targetEntity: FamilyQuotient::class, cascade: ['persist'], orphanRemoval: true)]
    private Collection $familyQuotients;

    #[Pure]
    public function __construct()
    {
        $this->residenceAreas = new ArrayCollection();
        $this->familyQuotients = new ArrayCollection();
    }

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

    public function getOrganization(): Organization
    {
        return $this->organization;
    }

    public function setOrganization(Organization $organization): self
    {
        $this->organization = $organization;
        return $this;
    }

    public function getApplyVat(): bool
    {
        return $this->applyVat;
    }

    public function setApplyVat(bool $applyVat): self
    {
        $this->applyVat = $applyVat;
        return $this;
    }

    public function getResidenceAreas(): Collection
    {
        return $this->residenceAreas;
    }

    public function addResidenceArea(ResidenceArea $residenceArea): self
    {
        if (!$this->residenceAreas->contains($residenceArea)) {
            $this->residenceAreas[] = $residenceArea;
            $residenceArea->setBillingSetting($this);
        }
        return $this;
    }

    public function removeResidenceArea(ResidenceArea $residenceArea): self
    {
        if ($this->residenceAreas->removeElement($residenceArea)) {
            // set the owning side to null (unless already changed)
            if ($residenceArea->getBillingSetting() === $this) {
                $residenceArea->setBillingSetting(null);
            }
        }
        return $this;
    }

    /**
     * @return Collection<int, FamilyQuotient>
     */
    public function getFamilyQuotients(): Collection
    {
        return $this->familyQuotients;
    }

    public function addFamilyQuotient(FamilyQuotient $familyQuotient): self
    {
        if (!$this->familyQuotients->contains($familyQuotient)) {
            $this->familyQuotients[] = $familyQuotient;
            $familyQuotient->setBillingSetting($this);
        }
        return $this;
    }

    public function removeFamilyQuotient(FamilyQuotient $familyQuotient): self
    {
        if ($this->familyQuotients->removeElement($familyQuotient)) {
            // set the owning side to null (unless already changed)
            if ($familyQuotient->getBillingSetting() === $this) {
                $familyQuotient->setBillingSetting(null);
            }
        }
        return $this;
    }
}
