<?php

declare(strict_types=1);

namespace App\Entity\Place;

use ApiPlatform\Metadata\ApiResource;
use App\Entity\Booking\Course;
use App\Entity\Booking\EducationalProject;
use App\Entity\Booking\Event;
use App\Entity\Booking\Examen;
use App\Entity\Product\Equipment;
// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Salle d'un bâtiment (Place).
 */
#[ApiResource(operations: [])]
// #[Auditable]
#[ORM\Entity]
class Room
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Place::class, inversedBy: 'rooms')]
    #[ORM\JoinColumn(nullable: false)]
    private Place $place;

    /** @var Collection<int, RoomControl> */
    #[ORM\OneToMany(targetEntity: RoomControl::class, mappedBy: 'room', cascade: ['persist'], orphanRemoval: true)]
    #[ORM\JoinColumn(nullable: false)]
    private Collection $controls;

    /** @var Collection<int, RoomRepair> */
    #[ORM\OneToMany(targetEntity: RoomRepair::class, mappedBy: 'room', cascade: ['persist'], orphanRemoval: true)]
    #[ORM\JoinColumn(nullable: false)]
    private Collection $repairs;

    /** @var Collection<int, Course> */
    #[ORM\OneToMany(targetEntity: Course::class, mappedBy: 'room')]
    private Collection $courses;

    /** @var Collection<int, EducationalProject> */
    #[ORM\OneToMany(targetEntity: EducationalProject::class, mappedBy: 'room')]
    private Collection $educationalProjects;

    /** @var Collection<int, Event> */
    #[ORM\OneToMany(targetEntity: Event::class, mappedBy: 'room')]
    private Collection $events;

    /** @var Collection<int, Examen> */
    #[ORM\OneToMany(targetEntity: Examen::class, mappedBy: 'room')]
    private Collection $examens;

    /** @var Collection<int, Equipment> */
    #[ORM\OneToMany(targetEntity: Equipment::class, mappedBy: 'roomStorage')]
    private Collection $equipmentStorages;

    /** @var Collection<int, Equipment> */
    #[ORM\OneToMany(targetEntity: Equipment::class, mappedBy: 'roomWhereIsUsed')]
    private Collection $equipmentUseds;

    public function __construct()
    {
        $this->controls = new ArrayCollection();
        $this->repairs = new ArrayCollection();
        $this->courses = new ArrayCollection();
        $this->educationalProjects = new ArrayCollection();
        $this->events = new ArrayCollection();
        $this->examens = new ArrayCollection();
        $this->equipmentStorages = new ArrayCollection();
        $this->equipmentUseds = new ArrayCollection();
    }

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

    public function getPlace(): Place
    {
        return $this->place;
    }

    public function setPlace(Place $place): self
    {
        $this->place = $place;

        return $this;
    }

    /**
     * @return Collection<int, RoomControl>
     */
    public function getControls(): Collection
    {
        return $this->controls;
    }

    public function addControl(RoomControl $control): self
    {
        if (!$this->controls->contains($control)) {
            $this->controls[] = $control;
            $control->setRoom($this);
        }

        return $this;
    }

    public function removeControl(RoomControl $control): self
    {
        if ($this->controls->removeElement($control)) {
            // set the owning side to null (unless already changed)
            if ($control->getRoom() === $this) {
                $control->setRoom(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, RoomRepair>
     */
    public function getRepairs(): Collection
    {
        return $this->repairs;
    }

    public function addRepair(RoomRepair $repair): self
    {
        if (!$this->repairs->contains($repair)) {
            $this->repairs[] = $repair;
            $repair->setRoom($this);
        }

        return $this;
    }

    public function removeRepair(RoomRepair $repair): self
    {
        if ($this->repairs->removeElement($repair)) {
            // set the owning side to null (unless already changed)
            if ($repair->getRoom() === $this) {
                $repair->setRoom(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Course>
     */
    public function getCourses(): Collection
    {
        return $this->courses;
    }

    public function addCourse(Course $course): self
    {
        if (!$this->courses->contains($course)) {
            $this->courses[] = $course;
            $course->setRoom($this);
        }

        return $this;
    }

    public function removeCourse(Course $course): self
    {
        if ($this->courses->removeElement($course)) {
            // set the owning side to null (unless already changed)
            if ($course->getRoom() === $this) {
                $course->setRoom(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, EducationalProject>
     */
    public function getEducationalProjects(): Collection
    {
        return $this->educationalProjects;
    }

    public function addEducationalProject(EducationalProject $educationalProject): self
    {
        if (!$this->educationalProjects->contains($educationalProject)) {
            $this->educationalProjects[] = $educationalProject;
            $educationalProject->setRoom($this);
        }

        return $this;
    }

    public function removeEducationalProject(EducationalProject $educationalProject): self
    {
        if ($this->educationalProjects->removeElement($educationalProject)) {
            // set the owning side to null (unless already changed)
            if ($educationalProject->getRoom() === $this) {
                $educationalProject->setRoom(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Event>
     */
    public function getEvents(): Collection
    {
        return $this->events;
    }

    public function addEvent(Event $event): self
    {
        if (!$this->events->contains($event)) {
            $this->events[] = $event;
            $event->setRoom($this);
        }

        return $this;
    }

    public function removeEvent(Event $event): self
    {
        if ($this->events->removeElement($event)) {
            // set the owning side to null (unless already changed)
            if ($event->getRoom() === $this) {
                $event->setRoom(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Examen>
     */
    public function getExamens(): Collection
    {
        return $this->examens;
    }

    public function addExamen(Examen $examen): self
    {
        if (!$this->examens->contains($examen)) {
            $this->examens[] = $examen;
            $examen->setRoom($this);
        }

        return $this;
    }

    public function removeExamen(Examen $examen): self
    {
        if ($this->examens->removeElement($examen)) {
            // set the owning side to null (unless already changed)
            if ($examen->getRoom() === $this) {
                $examen->setRoom(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Equipment>
     */
    public function getEquipmentStorages(): Collection
    {
        return $this->equipmentStorages;
    }

    public function addEquipmentStorage(Equipment $equipmentStorage): self
    {
        if (!$this->equipmentStorages->contains($equipmentStorage)) {
            $this->equipmentStorages[] = $equipmentStorage;
            $equipmentStorage->setRoomStorage($this);
        }

        return $this;
    }

    public function removeEquipmentStorage(Equipment $equipmentStorage): self
    {
        if ($this->equipmentStorages->removeElement($equipmentStorage)) {
            // set the owning side to null (unless already changed)
            if ($equipmentStorage->getRoomStorage() === $this) {
                $equipmentStorage->setRoomStorage(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Equipment>
     */
    public function getEquipmentUseds(): Collection
    {
        return $this->equipmentUseds;
    }

    public function addEquipmentUsed(Equipment $equipmentUsed): self
    {
        if (!$this->equipmentUseds->contains($equipmentUsed)) {
            $this->equipmentUseds[] = $equipmentUsed;
            $equipmentUsed->setRoomWhereIsUsed($this);
        }

        return $this;
    }

    public function removeEquipmentUsed(Equipment $equipmentUsed): self
    {
        if ($this->equipmentUseds->removeElement($equipmentUsed)) {
            // set the owning side to null (unless already changed)
            if ($equipmentUsed->getRoomWhereIsUsed() === $this) {
                $equipmentUsed->setRoomWhereIsUsed(null);
            }
        }

        return $this;
    }
}
