<?php
namespace App\Entity;
use App\Repository\AgentRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: AgentRepository::class)]
class Agent
{
#[ORM\Id]
#[ORM\Column(type:"string", length:36)]
private ?string $id = null;
#[ORM\Column(type:"text")]
private ?string $firstName = null;
#[ORM\Column(type:"text", nullable: true)]
private ?string $lastName = null;
#[ORM\Column(type:"text")]
private ?string $email = null;
#[ORM\Column(type:"boolean", options: ['default' => true])]
private ?bool $active = null;
#[ORM\Column(type:"boolean", options: ['default' => false])]
private ?bool $deleted = null;
#[ORM\Column]
private ?DateTimeImmutable $createdAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $updatedAt = null;
#[ORM\OneToMany(mappedBy: 'agent', targetEntity: Ticket::class)]
private ?Collection $tickets = null;
#[ORM\ManyToMany(targetEntity: Category::class, inversedBy: 'agents', fetch: 'EXTRA_LAZY')]
#[ORM\JoinTable(name: 'AgentCategories')]
private ?Collection $categories;
public function __construct(
$firstName, $email, $id = null, $lastName = null, $active = null, $deleted = null
) {
$this->id = $id;
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->createdAt = new DateTimeImmutable('now');
$this->updatedAt = new \DateTime('now');
$this->tickets = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->active = $active ?? true;
$this->deleted = $deleted ?? false;
}
public function getId(): ?string
{
return $this->id;
}
public function setId(string $id): self
{
$this->id = $id;
$this->markAsUpdated();
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
$this->markAsUpdated();
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
$this->markAsUpdated();
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
$this->markAsUpdated();
return $this;
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function markAsUpdated(): void
{
$this->updatedAt = new DateTimeImmutable();
}
/**
* @return Collection<int, Ticket>
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): self
{
if ($this->tickets && !$this->tickets->contains($ticket)) {
$this->tickets->add($ticket);
$ticket->setAgent($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): self
{
if ($this->tickets && $this->tickets->contains($ticket)) {
$this->tickets->removeElement($ticket);
if ($ticket->getAgent() === $this) {
$ticket->setAgent(null);
}
}
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
/**
* @param Collection<int, Category> $categories
*/
public function setCategories(Collection $categories): void
{
$this->categories = $categories;
}
public function isActive(): bool
{
return $this->active;
}
public function setActive(?bool $active): void
{
$this->active = $active;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(?bool $deleted): void
{
$this->deleted = $deleted;
}
}