<?php

declare(strict_types=1);

namespace App\Entity\Billing;

use ApiPlatform\Metadata\ApiResource;
use App\Entity\AccessWish\AccessWish;
use App\Entity\Organization\Organization;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * TODO: documenter.
 */
#[ApiResource(operations: [])]
#[ORM\Entity]
class BillSchedule
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private int $id;

    #[ORM\ManyToOne(targetEntity: Organization::class, cascade: [], inversedBy: 'billSchedules')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: false, onDelete: 'SET NULL')]
    protected Organization $organization;

    /** @var Collection<int, BillScheduleDate> */
    #[ORM\OneToMany(targetEntity: BillScheduleDate::class, mappedBy: 'billSchedule', cascade: ['persist'], orphanRemoval: true)]
    protected Collection $scheduleDates;

    /** @var Collection<int, AccessBilling> */
    #[ORM\OneToMany(targetEntity: AccessBilling::class, mappedBy: 'billSchedule', cascade: [], orphanRemoval: false)] // TODO: à revoir
    protected Collection $accessBilling;

    /** @var Collection<int, AccessWish> */
    #[ORM\OneToMany(targetEntity: AccessWish::class, mappedBy: 'billSchedule', cascade: [], orphanRemoval: false)] // TODO: à revoir
    protected Collection $accessWishes;

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

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

        return $this;
    }

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

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

        return $this;
    }

    public function getScheduleDates(): Collection
    {
        return $this->scheduleDates;
    }

    public function addScheduleDate(BillScheduleDate $scheduleDate): self
    {
        if (!$this->scheduleDates->contains($scheduleDate)) {
            $this->scheduleDates[] = $scheduleDate;
            $scheduleDate->setBillSchedule($this);
        }

        return $this;
    }

    public function removeScheduleDate(BillScheduleDate $scheduleDate): self
    {
        if ($this->scheduleDates->removeElement($scheduleDate)) {
            $scheduleDate->setBillSchedule(null);
        }

        return $this;
    }

    public function getAccessBilling(): Collection
    {
        return $this->accessBilling;
    }

    public function addAccessBilling(AccessBilling $accessBilling): self
    {
        if (!$this->accessBilling->contains($accessBilling)) {
            $this->accessBilling[] = $accessBilling;
            $accessBilling->setBillSchedule($this);
        }

        return $this;
    }

    public function removeAccessBilling(AccessBilling $accessBilling): self
    {
        if ($this->accessBilling->removeElement($accessBilling)) {
            //            $accessBilling->setBillSchedule(null);  // TODO: actuellement, pas nullable: conserver?
        }

        return $this;
    }

    public function getAccessWishes(): Collection
    {
        return $this->accessWishes;
    }

    public function addAccessWish(AccessWish $accessWish): self
    {
        if (!$this->accessWishes->contains($accessWish)) {
            $this->accessWishes[] = $accessWish;
            $accessWish->setBillSchedule($this);
        }

        return $this;
    }

    public function removeAccessWish(AccessWish $accessWish): self
    {
        if ($this->accessWishes->removeElement($accessWish)) {
            //            $accessWish->setBillSchedule(null);  // TODO: actuellement, pas nullable: conserver?
        }

        return $this;
    }
}
