<?php
namespace App\Entity;
use App\Repository\CategorieMarcheRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: CategorieMarcheRepository::class)]
#[ORM\Table(name: "CategorieMarche")]
class CategorieMarche
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: "Le libellé est obligatoire.")]
private ?string $libelle = null;
#[ORM\Column(length: 20, unique: true)]
private ?string $code = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\Column]
private bool $actif = true;
#[ORM\OneToMany(
mappedBy: 'categorieMarche',
targetEntity: Fournisseur::class
)]
private Collection $fournisseurs;
public function __construct()
{
$this->fournisseurs = new ArrayCollection();
}
// ===== Getters / Setters =====
public function getId(): ?int { return $this->id; }
public function getLibelle(): ?string { return $this->libelle; }
public function setLibelle(string $v): self { $this->libelle = $v; return $this; }
public function getCode(): ?string { return $this->code; }
public function setCode(string $v): self { $this->code = strtoupper($v); return $this; }
public function getDescription(): ?string { return $this->description; }
public function setDescription(?string $v): self { $this->description = $v; return $this; }
public function isActif(): bool { return $this->actif; }
public function setActif(bool $v): self { $this->actif = $v; return $this; }
public function getFournisseurs(): Collection { return $this->fournisseurs; }
public function __toString(): string
{
return $this->libelle ?? '';
}
}