<?php

namespace App\Entity\OnlineRegistration;

use ApiPlatform\Metadata\ApiResource;
use App\Entity\Organization\Organization;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure;

/**
 * Configuration de l'IEL pour une organization
 */
//#[ApiResource(operations: [])]
//#[ORM\Entity]
class OnlineRegistrationSettings
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\OneToOne(inversedBy: 'organization', targetEntity: Organization::class)]
    private Organization $organization;

    #[ORM\OneToMany(mappedBy: 'onlineRegistrationSettings', targetEntity: OnlineRegistrationOpeningPeriod::class, orphanRemoval: true)]
    private Collection $openingPeriods;

    #[ORM\OneToMany(mappedBy: 'onlineRegistrationSettingsNewEnrolments', targetEntity: OnlineRegistrationOpeningPeriod::class, orphanRemoval: true)]
    private Collection $openingPeriodsNewEnrolments;

    /**
     * TODO: compléter la doc
     * @var bool
     */
    #[ORM\Column]
    private bool $addNewStudents = false;

    /**
     * TODO: compléter la doc
     * @var bool
     */
    #[ORM\Column]
    private bool $addNewEducations = false;

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

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

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

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

    public function getOnlineRegistrationOpeningPeriods(): Collection
    {
        return $this->openingPeriods;
    }

    public function addOnlineRegistrationOpeningPeriod(OnlineRegistrationOpeningPeriod $openingPeriod): self
    {
        if (!$this->openingPeriods->contains($openingPeriod)) {
            $this->openingPeriods[] = $openingPeriod;
            $openingPeriod->setOnlineRegistrationSettings($this);
        }
        return $this;
    }

    public function removeOnlineRegistrationOpeningPeriod(OnlineRegistrationOpeningPeriod $openingPeriod): self
    {
        if ($this->openingPeriods->removeElement($openingPeriod)) {
            // set the owning side to null (unless already changed)
            if ($openingPeriod->getOnlineRegistrationSettings() === $this) {
                $openingPeriod->setOnlineRegistrationSettings(null);
            }
        }
        return $this;
    }

    public function getOnlineRegistrationOpeningPeriodsNewEnrolments(): Collection
    {
        return $this->openingPeriodsNewEnrolments;
    }

    public function addOnlineRegistrationOpeningPeriodNewEnrolments(OnlineRegistrationOpeningPeriod $openingPeriod): self
    {
        if (!$this->openingPeriodsNewEnrolments->contains($openingPeriod)) {
            $this->openingPeriodsNewEnrolments[] = $openingPeriod;
            $openingPeriod->setOnlineRegistrationSettingsNewEnrolments($this);
        }
        return $this;
    }

    public function removeOnlineRegistrationOpeningPeriodNewEnrolments(OnlineRegistrationOpeningPeriod $openingPeriod): self
    {
        if ($this->openingPeriodsNewEnrolments->removeElement($openingPeriod)) {
            // set the owning side to null (unless already changed)
            if ($openingPeriod->getOnlineRegistrationSettingsNewEnrolments() === $this) {
                $openingPeriod->setOnlineRegistrationSettingsNewEnrolments(null);
            }
        }
        return $this;
    }

    // TODO: confirmer que l'action est bien `can`
    public function canAddNewStudents(): bool
    {
        return $this->addNewStudents;
    }

    public function setAddNewStudents(bool $addNewStudents): void
    {
        $this->addNewStudents = $addNewStudents;
    }

    // TODO: confirmer que l'action est bien `can`
    public function canAddNewEducations(): bool
    {
        return $this->addNewEducations;
    }

    public function setAddNewEducations(bool $addNewEducations): void
    {
        $this->addNewEducations = $addNewEducations;
    }
}
