<?php
namespace App\Entity\Generic\Customer;
use App\Entity\BaseEntity;
use App\Entity\Website\Campaign;
use App\Entity\Website\Domains\Domain;
//use App\Entity\SubTransactions\ArzDigital;
//use App\Entity\SubTransactions\DonateKon;
//use App\Entity\SubTransactions\StreamMasters;
//use App\Entity\SubTransactions\VasetPal;
use App\Entity\VPN\Service\Service;
use App\Entity\Website\Sms\SmsIncome;
use App\Entity\Website\Telegram\AgentPublicBot\Bot;
use App\Entity\Website\Transaction;
use App\Entity\Website\Website\Website;
use App\Repository\Generic\CustomerRepository;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Table(
name: 'customer',
uniqueConstraints: [
new ORM\UniqueConstraint(name: 'shop_identifier_unique', columns: ['shop_id', 'identifier' , 'mobile'])
]
)]
#[ORM\Entity(repositoryClass: CustomerRepository::class)]
class Customer extends BaseEntity implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private mixed $firstName;
#[ORM\Column(length: 180 , nullable: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
#[ORM\Column(length: 20, nullable: true)]
private ?string $mobile = null;
#[ORM\Column(length: 180)]
private string $identifier; // ایمیل یا شماره موبایل (برای ورود)
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(type: 'boolean')]
private bool $isVerified = false;
#[ORM\Column(type: Types::BIGINT)]
private ?string $wallet = null;
#[ORM\ManyToOne(inversedBy: 'customers')]
#[ORM\JoinColumn(nullable: false)]
private ?Website $website = null;
public function getUserIdentifier(): string
{
return $this->identifier;
}
public function __toString()
{
return $this->getIdentifier();
}
#[ORM\Column(nullable: true)]
private ?int $verifyCode = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastName = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $passwordResetAt = null;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Bot::class)]
private Collection $bots;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $connectedTelegramUserId = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $lastlogin = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'customers')]
private ?self $presenter = null;
#[ORM\OneToMany(mappedBy: 'presenter', targetEntity: self::class)]
private Collection $users;
// ------------------------
// ------------------------
// ------------------------
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $image;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $lastLogin = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $lastBuy = null;
#[ORM\Column]
private ?int $subUserCount = null;
// /**
// * @var Collection<int, Service>
// */
// #[ORM\OneToMany(targetEntity: Service::class, mappedBy: 'owner')]
// private Collection $services;
#[ORM\Column(length: 255, nullable: true)]
private ?string $telegramChannel = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $customerText = null;
#[ORM\Column(nullable: true)]
private ?int $thisMonthCharge = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $userTrace = null;
// #[ORM\ManyToOne(inversedBy: 'users')]
// private ?Campaign $campaign = null;
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Domain::class)]
// private Collection $domains;
#[ORM\Column(nullable: true)]
private ?bool $isTelegramContact = null;
#[ORM\Column(nullable: true)]
private ?bool $isTelegramContactChecked = null;
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: \App\Entity\Telegram\AgentPublicBot\Bot::class)]
// private Collection $bots;
//
// #[ORM\OneToMany(mappedBy: 'author', targetEntity: Idea::class)]
// private Collection $ideas;
#[ORM\Column(length: 255, nullable: true)]
private ?string $cardNumberToCharge = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $advertiserMonthlyIncome = null;
// #[ORM\OneToMany(mappedBy: 'panelOwner', targetEntity: ArzDigital::class)]
// private Collection $arzDigitals;
#[ORM\Column(nullable: true)]
private ?int $VpnServicesCount = null;
#[ORM\ManyToOne(inversedBy: 'customers')]
private ?\App\Entity\Website\Campaign $campaign = null;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Transaction::class)]
private Collection $transactions;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: Transaction::class)]
private Collection $madeTransactions;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: \App\Entity\Website\Domains\Domain::class)]
private Collection $domains;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: SmsIncome::class)]
private Collection $smsIncomes;
//
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Ip::class)]
// private Collection $hetznerIps;
//
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Server::class)]
// private Collection $hetznerServers;
//
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: StreamMasters::class)]
// private Collection $streamMasters;
//
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: DonateKon::class)]
// private Collection $donateKons;
//
// #[ORM\OneToMany(mappedBy: 'creator', targetEntity: Ticket::class)]
// private Collection $tickets;
//
// #[ORM\OneToMany(mappedBy: 'author', targetEntity: TicketMessage::class)]
// private Collection $ticketMessages;
//
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: \App\Entity\SAAS\Domain\Domain::class)]
// private Collection $boughtDomains;
//
// #[ORM\OneToMany(mappedBy: 'owner', targetEntity: VasetPal::class)]
// private Collection $vasetPals;
public function getConnectedTelegramUserId(): ?array
{
return json_decode($this->connectedTelegramUserId , true);
}
public function setConnectedTelegramUserId(?array $connectedTelegramUserId): static
{
$this->connectedTelegramUserId = json_encode($connectedTelegramUserId);
return $this;
}
public function __construct()
{
parent::__construct();
$this->wallet = 0;
$this->setVerifyCode(random_int(00000 , 99999));
$this->bots = new ArrayCollection();
$this->users = new ArrayCollection();
$this->transactions = new ArrayCollection();
$this->madeTransactions = new ArrayCollection();
$this->domains = new ArrayCollection();
$this->smsIncomes = new ArrayCollection();
$this->setSubUserCount(0);
}
public function hasRole($role)
{
return in_array($role, $this->roles);
}
public function getId(): ?string
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getWallet(): ?string
{
return $this->wallet;
}
public function setWallet(string $wallet): static
{
$this->wallet = $wallet;
return $this;
}
public function getWebsite(): ?Website
{
return $this->website;
}
public function setWebsite(?Website $shop): static
{
$this->website = $shop;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): void
{
$this->mobile = $mobile;
}
public function getIdentifier(): string
{
return $this->identifier;
}
public function setIdentifier(string $identifier): void
{
$this->identifier = $identifier;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): void
{
$this->isVerified = $isVerified;
}
public function getVerifyCode(): ?int
{
return $this->verifyCode;
}
public function setVerifyCode(?int $verifyCode): void
{
$this->verifyCode = $verifyCode;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): static
{
$this->lastName = $lastName;
return $this;
}
public function getFirstName(): mixed
{
return $this->firstName;
}
public function setFirstName(mixed $firstName): void
{
$this->firstName = $firstName;
}
public function getPasswordResetAt(): ?\DateTimeInterface
{
return $this->passwordResetAt;
}
public function setPasswordResetAt(?\DateTimeInterface $passwordResetAt): static
{
$this->passwordResetAt = $passwordResetAt;
return $this;
}
/**
* @return Collection<int, Bot>
*/
public function getBots(): Collection
{
return $this->bots;
}
public function addBot(Bot $bot): static
{
if (!$this->bots->contains($bot)) {
$this->bots->add($bot);
$bot->setOwner($this);
}
return $this;
}
public function removeBot(Bot $bot): static
{
if ($this->bots->removeElement($bot)) {
// set the owning side to null (unless already changed)
if ($bot->getOwner() === $this) {
$bot->setOwner(null);
}
}
return $this;
}
public function getLastlogin(): ?\DateTimeInterface
{
return $this->lastlogin;
}
public function setLastlogin(?\DateTimeInterface $lastlogin): static
{
$this->lastlogin = $lastlogin;
return $this;
}
public function getPresenter(): ?self
{
return $this->presenter;
}
public function setPresenter(?self $presenter): static
{
$this->presenter = $presenter;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(self $customer): static
{
if (!$this->users->contains($customer)) {
$this->users->add($customer);
$customer->setPresenter($this);
}
return $this;
}
public function removeUser(self $customer): static
{
if ($this->users->removeElement($customer)) {
// set the owning side to null (unless already changed)
if ($customer->getPresenter() === $this) {
$customer->setPresenter(null);
}
}
return $this;
}
public function getVpnServicesCount(): ?int
{
return $this->VpnServicesCount;
}
public function setVpnServicesCount(?int $VpnServicesCount): void
{
$this->VpnServicesCount = $VpnServicesCount;
}
public function getLastBuy(): ?DateTimeInterface
{
return $this->lastBuy;
}
public function setLastBuy(?DateTimeInterface $lastBuy): void
{
$this->lastBuy = $lastBuy;
}
public function getSubUserCount(): ?int
{
return $this->subUserCount;
}
public function setSubUserCount(?int $subUserCount): void
{
$this->subUserCount = $subUserCount;
}
public function getTelegramChannel(): ?string
{
return $this->telegramChannel;
}
public function setTelegramChannel(?string $telegramChannel): void
{
$this->telegramChannel = $telegramChannel;
}
public function getCustomerText(): ?string
{
return $this->customerText;
}
public function setCustomerText(?string $customerText): void
{
$this->customerText = $customerText;
}
public function getThisMonthCharge(): ?int
{
return $this->thisMonthCharge;
}
public function setThisMonthCharge(?int $thisMonthCharge): void
{
$this->thisMonthCharge = $thisMonthCharge;
}
public function getUserTrace(): ?string
{
return $this->userTrace;
}
public function setUserTrace(?string $userTrace): void
{
$this->userTrace = $userTrace;
}
public function getIsTelegramContact(): ?bool
{
return $this->isTelegramContact;
}
public function setIsTelegramContact(?bool $isTelegramContact): void
{
$this->isTelegramContact = $isTelegramContact;
}
public function getIsTelegramContactChecked(): ?bool
{
return $this->isTelegramContactChecked;
}
public function setIsTelegramContactChecked(?bool $isTelegramContactChecked): void
{
$this->isTelegramContactChecked = $isTelegramContactChecked;
}
public function getCardNumberToCharge(): ?string
{
return $this->cardNumberToCharge;
}
public function setCardNumberToCharge(?string $cardNumberToCharge): void
{
$this->cardNumberToCharge = $cardNumberToCharge;
}
public function getAdvertiserMonthlyIncome(): ?string
{
return $this->advertiserMonthlyIncome;
}
public function setAdvertiserMonthlyIncome(?string $advertiserMonthlyIncome): void
{
$this->advertiserMonthlyIncome = $advertiserMonthlyIncome;
}
/**
* @return mixed
*/
public function getImage()
{
return $this->image;
}
/**
* @param mixed $image
*/
public function setImage($image): void
{
$this->image = $image;
}
public function getCampaign(): ?\App\Entity\Website\Campaign
{
return $this->campaign;
}
public function setCampaign(?\App\Entity\Website\Campaign $campaign): static
{
$this->campaign = $campaign;
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): static
{
if (!$this->transactions->contains($transaction)) {
$this->transactions->add($transaction);
$transaction->setOwner($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): static
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getOwner() === $this) {
$transaction->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getMadeTransactions(): Collection
{
return $this->madeTransactions;
}
public function addMadeTransaction(Transaction $madeTransaction): static
{
if (!$this->madeTransactions->contains($madeTransaction)) {
$this->madeTransactions->add($madeTransaction);
$madeTransaction->setAuthor($this);
}
return $this;
}
public function removeMadeTransaction(Transaction $madeTransaction): static
{
if ($this->madeTransactions->removeElement($madeTransaction)) {
// set the owning side to null (unless already changed)
if ($madeTransaction->getAuthor() === $this) {
$madeTransaction->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection<int, \App\Entity\Website\Domains\Domain>
*/
public function getDomains(): Collection
{
return $this->domains;
}
public function addDomain(\App\Entity\Website\Domains\Domain $domain): static
{
if (!$this->domains->contains($domain)) {
$this->domains->add($domain);
$domain->setOwner($this);
}
return $this;
}
public function removeDomain(\App\Entity\Website\Domains\Domain $domain): static
{
if ($this->domains->removeElement($domain)) {
// set the owning side to null (unless already changed)
if ($domain->getOwner() === $this) {
$domain->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, SmsIncome>
*/
public function getSmsIncomes(): Collection
{
return $this->smsIncomes;
}
public function addSmsIncome(SmsIncome $smsIncome): static
{
if (!$this->smsIncomes->contains($smsIncome)) {
$this->smsIncomes->add($smsIncome);
$smsIncome->setOwner($this);
}
return $this;
}
public function removeSmsIncome(SmsIncome $smsIncome): static
{
if ($this->smsIncomes->removeElement($smsIncome)) {
// set the owning side to null (unless already changed)
if ($smsIncome->getOwner() === $this) {
$smsIncome->setOwner(null);
}
}
return $this;
}
}