<?php

namespace App\Entity;

use App\Repository\ProduitRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

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

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

    #[ORM\Column]
    private ?float $prix = null;

    #[ORM\Column(type: Types::TEXT)]
    private ?string $description = null;

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

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

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

    public function getNom(): ?string
    {
        return $this->nom;
    }

    public function setNom(string $nom): static
    {
        $this->nom = $nom;

        return $this;
    }

    public function getPrix(): ?float
    {
        return $this->prix;
    }

    public function setPrix(float $prix): static
    {
        $this->prix = $prix;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

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

        return $this;
    }

    /**
     * @return Collection<int, ObjetPanier>
     */
    public function getObjetPaniers(): Collection
    {
        return $this->objetPaniers;
    }

    public function addObjetPanier(ObjetPanier $objetPanier): static
    {
        if (!$this->objetPaniers->contains($objetPanier)) {
            $this->objetPaniers->add($objetPanier);
            $objetPanier->setProduit($this);
        }

        return $this;
    }

    public function removeObjetPanier(ObjetPanier $objetPanier): static
    {
        if ($this->objetPaniers->removeElement($objetPanier)) {
            // set the owning side to null (unless already changed)
            if ($objetPanier->getProduit() === $this) {
                $objetPanier->setProduit(null);
            }
        }

        return $this;
    }
}
