<?php
namespace App\Entity;
use App\Repository\AppAccountRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Doctrine\ORM\Mapping\JoinColumn;
#[ORM\Entity(repositoryClass: AppAccountRepository::class)]
#[ORM\Table(name: 'tb_app_accounts')]
#[ORM\HasLifecycleCallbacks]
#[UniqueEntity("username", message: "Ce code client est déjà utilisé")]
class AppAccount implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer", unique: true)]
private ?int $id;
#[ORM\Column(type: 'string', length: 50, nullable: false)]
private ?string $code;
#[ORM\Column(type: 'string', length: 50, nullable: false)]
#[Assert\NotBlank(message: "Saisir un code utilisateur")]
private ?string $username;
#[ORM\Column(type: 'string', length: 200, nullable: false)]
private ?string $password;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $activated;
#[ORM\Column(type: 'string', length: 20, nullable: false)]
#[Assert\NotBlank(message: "Le code client ne peut pas être vide")]
private ?string $clientCode;
#[ORM\Column(type: 'string', length: 100, nullable: false)]
#[Assert\NotBlank(message: "Saisir le nom du client")]
private ?string $name;
#[ORM\Column(type: 'string', length: 20, nullable: true)]
#[Assert\NotBlank(message: "Saisir un numéro de téléphone")]
#[Assert\Regex(pattern: "/\d/", message: "Le numéro de téléphone ne contient que des chiffres")]
private $phone;
#[ORM\Column(type: 'string', length: 50, nullable: false)]
#[Assert\Email(message: "Saisir un email valide")]
private ?string $email;
#[ORM\Column(type: 'datetime', nullable: false)]
private \DateTimeInterface $createdAt;
#[ORM\Column(type: 'datetime', nullable: false)]
private ?\DateTimeInterface $modifiedAt;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $createdBy;
#[ORM\ManyToOne(targetEntity: Country::class)]
#[Assert\NotBlank(message: "Choisir le code pays")]
private ?Country $country;
#[ORM\Column(type: 'integer', nullable: false)]
private ?int $step;
#[ORM\Column(type: 'boolean', nullable: false)]
private bool $passwordSent;
#[ORM\ManyToMany(targetEntity: Module::class)]
#[ORM\JoinTable(name: 'tb_app_accounts_modules')]
#[ORM\JoinColumn(name: 'app_account_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'modules_id', referencedColumnName: 'id')]
private Collection $modules;
#[ORM\Column(type: 'integer', nullable: true)]
private int $nbLogin;
#[ORM\OneToMany(mappedBy: 'appAccount', targetEntity: Compte::class, orphanRemoval: true)]
private Collection $comptes;
#[ORM\OneToMany(mappedBy: 'appAccount', targetEntity: ClientDebit::class)]
private Collection $clientDebits;
#[ORM\OneToMany(mappedBy: 'accounts', targetEntity: FrequentlyUsedAccount::class, orphanRemoval: true)]
private Collection $frequentlyUsedAccounts;
#[ORM\OneToMany(mappedBy: 'appAccount', targetEntity: LoginAttempt::class)]
private Collection $loginAttempts;
#[ORM\OneToMany(mappedBy: 'appAccount', targetEntity: AppAccountNotification::class)]
private Collection $appAccountNotifications;
#[ORM\OneToMany(mappedBy: 'account', targetEntity: TransactionAmountAccount::class)]
private Collection $transactionAmountAccounts;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->passwordSent = false;
$this->modules = new ArrayCollection();
$this->nbLogin = 0;
$this->comptes = new ArrayCollection();
$this->clientDebits = new ArrayCollection();
$this->frequentlyUsedAccounts = new ArrayCollection();
$this->loginAttempts = new ArrayCollection();
$this->appAccountNotifications = new ArrayCollection();
$this->transactionAmountAccounts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getActivated(): ?bool
{
return $this->activated;
}
public function setActivated(?bool $activated): self
{
$this->activated = $activated;
return $this;
}
public function getClientCode(): ?string
{
return $this->clientCode;
}
public function setClientCode(?string $clientCode): self
{
$this->clientCode = $clientCode;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modifiedAt;
}
public function setModifiedAt(?\DateTimeInterface $modifiedAt): self
{
$this->modifiedAt = $modifiedAt;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
public function getStep(): ?int
{
return $this->step;
}
public function setStep(?int $step): self
{
$this->step = $step;
return $this;
}
/**
* @ORM\PreUpdate
*/
public function onUpdate() {
$this->modifiedAt = new \DateTime();
}
public function getRoles()
{
// TODO: Implement getRoles() method.
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function getPasswordSent(): ?bool
{
return $this->passwordSent;
}
public function setPasswordSent(?bool $passwordSent): self
{
$this->passwordSent = $passwordSent;
return $this;
}
/**
* @return Collection|Module[]
*/
public function getModules(): Collection
{
return $this->modules;
}
public function addModule(Module $module): self
{
if (!$this->modules->contains($module)) {
$this->modules[] = $module;
}
return $this;
}
public function removeModule(Module $module): self
{
$this->modules->removeElement($module);
return $this;
}
public function getNbLogin(): ?int
{
return $this->nbLogin;
}
public function setNbLogin(?int $nbLogin): self
{
$this->nbLogin = $nbLogin;
return $this;
}
/**
* @return Collection|Compte[]
*/
public function getComptes(): Collection
{
return $this->comptes;
}
public function addCompte(Compte $compte): self
{
if (!$this->comptes->contains($compte)) {
$this->comptes[] = $compte;
$compte->setAppAccount($this);
}
return $this;
}
public function removeCompte(Compte $compte): self
{
if ($this->comptes->removeElement($compte)) {
// set the owning side to null (unless already changed)
if ($compte->getAppAccount() === $this) {
$compte->setAppAccount(null);
}
}
return $this;
}
/**
* @return Collection|ClientDebit[]
*/
public function getClientDebits(): Collection
{
return $this->clientDebits;
}
public function addClientDebit(ClientDebit $clientDebit): self
{
if (!$this->clientDebits->contains($clientDebit)) {
$this->clientDebits[] = $clientDebit;
$clientDebit->setAppAccount($this);
}
return $this;
}
public function removeClientDebit(ClientDebit $clientDebit): self
{
if ($this->clientDebits->removeElement($clientDebit)) {
// set the owning side to null (unless already changed)
if ($clientDebit->getAppAccount() === $this) {
$clientDebit->setAppAccount(null);
}
}
return $this;
}
/**
* @return Collection|FrequentlyUsedAccount[]
*/
public function getFrequentlyUsedAccounts(): Collection
{
return $this->frequentlyUsedAccounts;
}
public function addFrequentlyUsedAccount(FrequentlyUsedAccount $frequentlyUsedAccount): self
{
if (!$this->frequentlyUsedAccounts->contains($frequentlyUsedAccount)) {
$this->frequentlyUsedAccounts[] = $frequentlyUsedAccount;
$frequentlyUsedAccount->setAccount($this);
}
return $this;
}
public function removeFrequentlyUsedAccount(FrequentlyUsedAccount $frequentlyUsedAccount): self
{
if ($this->frequentlyUsedAccounts->removeElement($frequentlyUsedAccount)) {
// set the owning side to null (unless already changed)
if ($frequentlyUsedAccount->getAccount() === $this) {
$frequentlyUsedAccount->setAccount(null);
}
}
return $this;
}
/**
* @return Collection<int, LoginAttempt>
*/
public function getLoginAttempts(): Collection
{
return $this->loginAttempts;
}
public function addLoginAttempt(LoginAttempt $loginAttempt): static
{
if (!$this->loginAttempts->contains($loginAttempt)) {
$this->loginAttempts->add($loginAttempt);
$loginAttempt->setAppAccount($this);
}
return $this;
}
public function removeLoginAttempt(LoginAttempt $loginAttempt): static
{
if ($this->loginAttempts->removeElement($loginAttempt)) {
// set the owning side to null (unless already changed)
if ($loginAttempt->getAppAccount() === $this) {
$loginAttempt->setAppAccount(null);
}
}
return $this;
}
/**
* @return Collection<int, AppAccountNotification>
*/
public function getAppAccountNotifications(): Collection
{
return $this->appAccountNotifications;
}
public function addAppAccountNotification(AppAccountNotification $appAccountNotification): static
{
if (!$this->appAccountNotifications->contains($appAccountNotification)) {
$this->appAccountNotifications->add($appAccountNotification);
$appAccountNotification->setAppAccount($this);
}
return $this;
}
public function removeAppAccountNotification(AppAccountNotification $appAccountNotification): static
{
if ($this->appAccountNotifications->removeElement($appAccountNotification)) {
// set the owning side to null (unless already changed)
if ($appAccountNotification->getAppAccount() === $this) {
$appAccountNotification->setAppAccount(null);
}
}
return $this;
}
/**
* @return Collection<int, TransactionAmountAccount>
*/
public function getTransactionAmountAccounts(): Collection
{
return $this->transactionAmountAccounts;
}
public function addTransactionAmountAccount(TransactionAmountAccount $transactionAmountAccount): static
{
if (!$this->transactionAmountAccounts->contains($transactionAmountAccount)) {
$this->transactionAmountAccounts->add($transactionAmountAccount);
$transactionAmountAccount->setAccount($this);
}
return $this;
}
public function removeTransactionAmountAccount(TransactionAmountAccount $transactionAmountAccount): static
{
if ($this->transactionAmountAccounts->removeElement($transactionAmountAccount)) {
// set the owning side to null (unless already changed)
if ($transactionAmountAccount->getAccount() === $this) {
$transactionAmountAccount->setAccount(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->getClientCode()." - ".$this->getName();
}
}