<?php

namespace App\Entity\CollectifData;

use App\Entity\Dream\Dream;
use App\Entity\ProjectBoost\ProjectBoost;
use App\Entity\ProjectInspiring\ProjectInspiring;
use App\Entity\Revolt\Revolt;
use App\Entity\Territory\Territory;
use App\Entity\User\User;
use App\Repository\CollectifData\CollectifDataRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\PietroBundle\Model\AbstractData as PietroAbstractData;

/**
 * @ORM\Entity(repositoryClass=CollectifDataRepository::class)
 */
class CollectifData extends PietroAbstractData
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $name;

    /**
     * @ORM\ManyToOne(targetEntity=User::class, inversedBy="collectifData")
     */
    private $user;

    /**
     * @ORM\Column(type="integer")
     */
    private $nbParticipant;

    /**
     * @ORM\OneToMany(targetEntity=Revolt::class, mappedBy="collectifData", cascade={"persist", "remove"})
     */
    protected $revolt;

    /**
     * @ORM\OneToMany(targetEntity=Dream::class, mappedBy="collectifData", cascade={"persist", "remove"})
     */
    protected $dream;

    /**
     * @ORM\OneToMany(targetEntity=ProjectBoost::class, mappedBy="collectifData", cascade={"persist", "remove"})
     */
    protected $projectBoost;

    /**
     * @ORM\OneToMany(targetEntity=ProjectInspiring::class, mappedBy="collectifData", cascade={"persist", "remove"})
     */
    protected $projectInspiring;

    /**
     * @ORM\ManyToOne(targetEntity=Territory::class, inversedBy="collectifData")
     */
    protected $territory;

    public function __construct()
    {
        $this->revolt = new ArrayCollection();
        $this->dream = new ArrayCollection();
        $this->projectBoost = new ArrayCollection();
        $this->projectInspiring = new ArrayCollection();
    }

    public function __toString()
    {
        return $this->nbParticipant . " participants";
    }

    public function getResume()
    {
        return count($this->getRevolt()) . " révolte(s) - " . count($this->getDream()) . " rêve(s) - " . count(
                $this->getProjectBoost()
            ) . " projet(s) boosté(s) - " . count($this->getProjectInspiring()) . " projets inspirants";
    }

    public function getNbDream(): string
    {
        return count($this->getDream());
    }

    public function getNbRevolt(): string
    {
        return count($this->getRevolt());
    }

    public function getNbProjectBoost(): string
    {
        return count($this->getProjectBoost());
    }

    public function getNbProjectInspiring(): string
    {
        return count($this->getProjectInspiring());
    }

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

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(?User $user): self
    {
        $this->user = $user;

        return $this;
    }

    public function getNbParticipant(): ?int
    {
        return $this->nbParticipant;
    }

    public function setNbParticipant(int $nbParticipant): self
    {
        $this->nbParticipant = $nbParticipant;

        return $this;
    }

    /**
     * @return Collection|Revolt[]
     */
    public function getRevolt(): Collection
    {
        return $this->revolt;
    }

    public function addRevolt(Revolt $revolt): self
    {
        if (!$this->revolt->contains($revolt)) {
            $this->revolt[] = $revolt;
            $revolt->setCollectifData($this);
        }

        return $this;
    }

    public function removeRevolt(Revolt $revolt): self
    {
        if ($this->revolt->removeElement($revolt)) {
            // set the owning side to null (unless already changed)
            if ($revolt->getCollectifData() === $this) {
                $revolt->setCollectifData(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Dream[]
     */
    public function getDream(): Collection
    {
        return $this->dream;
    }

    public function addDream(Dream $dream): self
    {
        if (!$this->dream->contains($dream)) {
            $this->dream[] = $dream;
            $dream->setCollectifData($this);
        }

        return $this;
    }

    public function removeDream(Dream $dream): self
    {
        if ($this->dream->removeElement($dream)) {
            // set the owning side to null (unless already changed)
            if ($dream->getCollectifData() === $this) {
                $dream->setCollectifData(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|ProjectBoost[]
     */
    public function getProjectBoost(): Collection
    {
        return $this->projectBoost;
    }

    public function addProjectBoost(ProjectBoost $projectBoost): self
    {
        if (!$this->projectBoost->contains($projectBoost)) {
            $this->projectBoost[] = $projectBoost;
            $projectBoost->setCollectifData($this);
        }

        return $this;
    }

    public function removeProjectBoost(ProjectBoost $projectBoost): self
    {
        if ($this->projectBoost->removeElement($projectBoost)) {
            // set the owning side to null (unless already changed)
            if ($projectBoost->getCollectifData() === $this) {
                $projectBoost->setCollectifData(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|ProjectInspiring[]
     */
    public function getProjectInspiring(): Collection
    {
        return $this->projectInspiring;
    }

    public function addProjectInspiring(ProjectInspiring $projectInspiring): self
    {
        if (!$this->projectInspiring->contains($projectInspiring)) {
            $this->projectInspiring[] = $projectInspiring;
            $projectInspiring->setCollectifData($this);
        }

        return $this;
    }

    public function removeProjectInspiring(ProjectInspiring $projectInspiring): self
    {
        if ($this->projectInspiring->removeElement($projectInspiring)) {
            // set the owning side to null (unless already changed)
            if ($projectInspiring->getCollectifData() === $this) {
                $projectInspiring->setCollectifData(null);
            }
        }

        return $this;
    }

    public function getTerritory(): ?Territory
    {
        return $this->territory;
    }

    public function setTerritory(?Territory $territory): self
    {
        $this->territory = $territory;

        return $this;
    }
}
