<?php

declare(strict_types=1);

namespace App\Entity\Place;

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

/**
 * Lieu physique, bâtiment.
 */
// #[Auditable]
#[ApiResource(operations: [])]
#[ORM\Entity]
class Place extends AbstractPlace
{
    /** @var Collection<int, Event> */
    #[ORM\OneToMany(targetEntity: Event::class, mappedBy: 'place')]
    private Collection $events;

    #[ORM\ManyToOne(inversedBy: 'places')]
    private ?Organization $organization;

    /** @var Collection<int, ContactPoint> */
    #[ORM\ManyToMany(targetEntity: ContactPoint::class, inversedBy: 'place', cascade: ['persist'])]
    #[ORM\JoinTable(name: 'place_contactpoint')]
    #[ORM\JoinColumn(name: 'contactPoint_id', referencedColumnName: 'id', unique: true)]
    #[ORM\InverseJoinColumn(name: 'place_id', referencedColumnName: 'id')]
    private Collection $contactpoint;

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

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

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

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

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

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

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

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

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

    public function getEvents(): Collection
    {
        return $this->events;
    }

    public function addEvent(Event $event): self
    {
        if (!$this->events->contains($event)) {
            $this->events[] = $event;
            $event->setPlace($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->getPlace() === $this) {
                $event->setPlace(null);
            }
        }

        return $this;
    }

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

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

        return $this;
    }

    /**
     * @return Collection<int, ContactPoint>
     */
    public function getContactpoint(): Collection
    {
        return $this->contactpoint;
    }

    public function addContactpoint(ContactPoint $contactpoint): self
    {
        if (!$this->contactpoint->contains($contactpoint)) {
            $this->contactpoint[] = $contactpoint;
        }

        return $this;
    }

    public function removeContactpoint(ContactPoint $contactpoint): self
    {
        $this->contactpoint->removeElement($contactpoint);

        return $this;
    }

    /**
     * @return Collection<int, Room>
     */
    public function getRooms(): Collection
    {
        return $this->rooms;
    }

    public function addRoom(Room $room): self
    {
        if (!$this->rooms->contains($room)) {
            $this->rooms[] = $room;
            $room->setPlace($this);
        }

        return $this;
    }

    public function removeRoom(Room $room): self
    {
        $this->rooms->removeElement($room);

        return $this;
    }

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

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

        return $this;
    }

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

        return $this;
    }

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

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

        return $this;
    }

    public function removeRepair(PlaceRepair $repair): self
    {
        if ($this->repairs->removeElement($repair)) {
            // set the owning side to null (unless already changed)
            if ($repair->getPlace() === $this) {
                $repair->setPlace(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->setPlace($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->getPlace() === $this) {
                $course->setPlace(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->setPlace($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->getPlace() === $this) {
                $educationalProject->setPlace(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->setPlace($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->getPlace() === $this) {
                $examen->setPlace(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->setPlaceStorage($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->getPlaceStorage() === $this) {
                $equipmentStorage->setPlaceStorage(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->setPlaceWhereIsUsed($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->getPlaceWhereIsUsed() === $this) {
                $equipmentUsed->setPlaceWhereIsUsed(null);
            }
        }

        return $this;
    }
}
