<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ProjectsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ProjectsRepository::class)]
#[ApiResource]
class Projects implements \Stringable
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 255)]
    private ?string $name = null;

    #[ORM\Column(type: 'string', length: 255)]
    private ?string $description = null;

    #[ORM\Column(type: 'string', length: 255)]
    private ?string $url = null;

    #[ORM\Column(type: 'datetime_immutable')]
    private ?\DateTimeImmutable $createdAt = null;

    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    private ?string $teaserImage = null;

    #[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'projects')]
    private $developer;

    public function __construct()
    {
        $this->developer = new ArrayCollection();
    }

    /**
     * @return string|null
     */
    public function __toString(): string
    {
        return (string) $this->name;
    }

    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 getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(string $Description): self
    {
        $this->description = $Description;

        return $this;
    }

    public function getURL(): ?string
    {
        return $this->url;
    }

    public function setURL(string $url): self
    {
        $this->url = $url;

        return $this;
    }

    public function getCreatedAt(): ?\DateTimeImmutable
    {
        return $this->createdAt;
    }

    public function setCreatedAt(\DateTimeImmutable $createdAt): self
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    public function getTeaserImage(): ?string
    {
        return $this->teaserImage;
    }

    public function setTeaserImage(?string $teaserImage): self
    {
        $this->teaserImage = $teaserImage;

        return $this;
    }

    /**
     * @return Collection<int, User>
     */
    public function getDeveloper(): Collection
    {
        return $this->developer;
    }

    public function addDeveloper(User $developer): self
    {
        if (!$this->developer->contains($developer)) {
            $this->developer[] = $developer;
        }

        return $this;
    }

    public function removeDeveloper(User $developer): self
    {
        $this->developer->removeElement($developer);

        return $this;
    }
}