<?php
namespace App\Entity;
use App\Repository\OrganizationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\ServiceUsage;
use Symfony\Component\Validator\Constraints as Assert;
use App\Billing\Model\BillablePartyInterface;
#[ORM\Entity(repositoryClass: OrganizationRepository::class)]
class Organization implements BillablePartyInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: "Le nom de l'organisation est obligatoire.")]
private ?string $nom = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $matriculeFiscale = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $adresse = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $telephone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\Email(message: "L'email '{{ value }}' n'est pas un email valide.")]
private ?string $email = null;
#[ORM\OneToMany(mappedBy: 'organization', targetEntity: User::class)]
private Collection $users;
#[ORM\OneToMany(mappedBy: 'organization', targetEntity: ServiceUsage::class)]
private Collection $serviceUsages;
public function __construct()
{
$this->users = new ArrayCollection();
$this->serviceUsages = 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 getMatriculeFiscale(): ?string
{
return $this->matriculeFiscale;
}
public function setMatriculeFiscale(?string $matriculeFiscale): static
{
$this->matriculeFiscale = $matriculeFiscale;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): static
{
$this->adresse = $adresse;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): static
{
$this->telephone = $telephone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): static
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setOrganization($this);
}
return $this;
}
public function removeUser(User $user): static
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getOrganization() === $this) {
$user->setOrganization(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->nom ?? '';
}
// BillablePartyInterface implementation
public function getBillingName(): string
{
return $this->nom;
}
public function getBillingAddress(): ?string
{
return $this->adresse;
}
public function getTaxId(): ?string
{
return $this->matriculeFiscale;
}
public function getBillingEmail(): ?string
{
return $this->email;
}
}