<?php

namespace App\Entity;

use App\Repository\ImageRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ImageRepository::class)]
class Image
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

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

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

    #[ORM\Column]
    private ?int $size = null;

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

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

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

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

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

        return $this;
    }

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

    public function setUrl(string $url): static
    {
        $this->url = $url;

        return $this;
    }

    public function getSize(): ?int
    {
        return $this->size;
    }

    public function setSize(int $size): static
    {
        $this->size = $size;

        return $this;
    }

    /**
     * @return Collection<int, NewsImage>
     */
    public function getNewsImages(): Collection
    {
        return $this->newsImages;
    }

    public function addNewsImage(NewsImage $newsImage): static
    {
        if (!$this->newsImages->contains($newsImage)) {
            $this->newsImages->add($newsImage);
            $newsImage->setImage($this);
        }

        return $this;
    }

    public function removeNewsImage(NewsImage $newsImage): static
    {
        if ($this->newsImages->removeElement($newsImage)) {
            // set the owning side to null (unless already changed)
            if ($newsImage->getImage() === $this) {
                $newsImage->setImage(null);
            }
        }

        return $this;
    }
}
