<?php

declare(strict_types=1);

namespace App\Entity\Booking;

use ApiPlatform\Metadata\ApiResource;
use App\Entity\Organization\Organization;
// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table OrganizationHoliday, et supprimer l'attribut discr.
 *
 * Périodes de vacances d'une Organization
 */
#[ApiResource(operations: [])]
// #[Auditable]
#[ORM\Entity]
class OrganizationHoliday extends AbstractBooking
{
    /** @var Collection<int, OrganizationHolidayRecur> */
    #[ORM\OneToMany(targetEntity: OrganizationHolidayRecur::class, mappedBy: 'event', cascade: ['persist', 'remove'])]
    protected Collection $eventRecur;

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

    public function __construct()
    {
        $this->eventRecur = new ArrayCollection();
        parent::__construct();
    }

    /**
     * @return Collection<int, OrganizationHolidayRecur>
     */
    public function getEventRecur(): Collection
    {
        return $this->eventRecur;
    }

    public function addEventRecur(OrganizationHolidayRecur $eventRecur): self
    {
        if (!$this->eventRecur->contains($eventRecur)) {
            $this->eventRecur[] = $eventRecur;
            $eventRecur->setEvent($this);
        }

        return $this;
    }

    public function removeEventRecur(OrganizationHolidayRecur $eventRecur): self
    {
        if ($this->eventRecur->removeElement($eventRecur)) {
            // set the owning side to null (unless already changed)
            if ($eventRecur->getEvent() === $this) {
                $eventRecur->setEvent(null);
            }
        }

        return $this;
    }

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

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

        return $this;
    }
}
