<?php
namespace App\Entity;
use App\Repository\ProduitVariantRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProduitVariantRepository::class)]
class ProduitVariant
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $size = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $color = null;
// ── Values for up to 3 dimensions (e.g. "Lavender", "50ml", "Red") ──
#[ORM\Column(length: 255, nullable: true)]
private ?string $optionLabel = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $optionLabel2 = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $optionLabel3 = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $prix = null;
// ── per-variant cost (for profit reports); nullable, falls back to product cost ──
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $cost_price = null;
#[ORM\ManyToOne(inversedBy: 'produitVariants')]
#[ORM\JoinColumn(nullable: false)]
private ?Produit $produit = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $qtt = null;
#[ORM\OneToMany(mappedBy: 'produitVariant', targetEntity: CommandeDetails::class)]
private Collection $commandeDetails;
#[ORM\ManyToOne(inversedBy: 'produitVariants')]
private ?ParamColor $paramColor = null;
#[ORM\ManyToOne(inversedBy: 'produitVariants')]
private ?ParamSize $paramSize = null;
// ── images that belong to this variant ──
#[ORM\OneToMany(mappedBy: 'produitVariant', targetEntity: Image::class)]
private Collection $images;
public function __construct()
{
$this->commandeDetails = new ArrayCollection();
$this->images = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getOptionLabel(): ?string
{
return $this->optionLabel;
}
public function setOptionLabel(?string $optionLabel): static
{
$this->optionLabel = $optionLabel;
return $this;
}
public function getOptionLabel2(): ?string
{
return $this->optionLabel2;
}
public function setOptionLabel2(?string $optionLabel2): static
{
$this->optionLabel2 = $optionLabel2;
return $this;
}
public function getOptionLabel3(): ?string
{
return $this->optionLabel3;
}
public function setOptionLabel3(?string $optionLabel3): static
{
$this->optionLabel3 = $optionLabel3;
return $this;
}
public function getPrix(): ?string
{
return $this->prix;
}
public function setPrix(?string $prix): static
{
$this->prix = $prix;
return $this;
}
public function getCostPrice(): ?string
{
return $this->cost_price;
}
public function setCostPrice(?string $cost_price): static
{
$this->cost_price = $cost_price;
return $this;
}
public function getProduit(): ?Produit
{
return $this->produit;
}
public function setProduit(?Produit $produit): static
{
$this->produit = $produit;
return $this;
}
public function getQtt(): ?string
{
return $this->qtt;
}
public function setQtt(?string $qtt): static
{
$this->qtt = $qtt;
return $this;
}
public function __toString(): string{
$parts = array_filter([$this->optionLabel, $this->optionLabel2, $this->optionLabel3]);
if (!empty($parts)) {
return implode(' · ', $parts);
}
return (string) ($this->color ?? '');
}
/**
* @return Collection<int, CommandeDetails>
*/
public function getCommandeDetails(): Collection
{
return $this->commandeDetails;
}
public function addCommandeDetail(CommandeDetails $commandeDetail): static
{
if (!$this->commandeDetails->contains($commandeDetail)) {
$this->commandeDetails->add($commandeDetail);
$commandeDetail->setProduitVariant($this);
}
return $this;
}
public function removeCommandeDetail(CommandeDetails $commandeDetail): static
{
if ($this->commandeDetails->removeElement($commandeDetail)) {
if ($commandeDetail->getProduitVariant() === $this) {
$commandeDetail->setProduitVariant(null);
}
}
return $this;
}
public function getParamColor(): ?ParamColor
{
return $this->paramColor;
}
public function setParamColor(?ParamColor $paramColor): static
{
$this->paramColor = $paramColor;
return $this;
}
public function getParamSize(): ?ParamSize
{
return $this->paramSize;
}
public function setParamSize(?ParamSize $paramSize): static
{
$this->paramSize = $paramSize;
return $this;
}
/**
* @return Collection<int, Image>
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): static
{
if (!$this->images->contains($image)) {
$this->images->add($image);
$image->setProduitVariant($this);
}
return $this;
}
public function removeImage(Image $image): static
{
if ($this->images->removeElement($image)) {
if ($image->getProduitVariant() === $this) {
$image->setProduitVariant(null);
}
}
return $this;
}
}