<?php
namespace App\Entity\Abonnent;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'device_registrations')]
#[ORM\Index(columns: ['user_id', 'is_active'])]
#[ORM\Index(columns: ['device_id'])]
#[ORM\UniqueConstraint(columns: ['user_id', 'device_id'])]
class DeviceRegistration
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Abonnent::class)]
#[ORM\JoinColumn(name: 'user_id', nullable: false)]
private Abonnent $user;
#[ORM\Column(type: 'string', length: 64)]
private string $deviceId;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $deviceName = null;
#[ORM\Column(type: 'string', length: 45, nullable: true)]
private ?string $ipAddress = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $userAgent = null;
#[ORM\Column(type: 'datetime')]
private \DateTime $firstLogin;
#[ORM\Column(type: 'datetime')]
private \DateTime $lastActivity;
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private bool $isActive = true;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $refreshToken = null;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private ?string $logoutReason = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTime $logoutAt = null;
public function __construct(Abonnent $user, string $deviceId)
{
$this->user = $user;
$this->deviceId = $deviceId;
$this->firstLogin = new \DateTime();
$this->lastActivity = new \DateTime();
}
// Getters and setters...
public function getId(): ?int
{
return $this->id;
}
public function getUser(): Abonnent
{
return $this->user;
}
public function getDeviceId(): string
{
return $this->deviceId;
}
public function getDeviceName(): ?string
{
return $this->deviceName;
}
public function setDeviceName(?string $deviceName): self
{
$this->deviceName = $deviceName;
return $this;
}
public function getIpAddress(): ?string
{
return $this->ipAddress;
}
public function setIpAddress(?string $ipAddress): self
{
$this->ipAddress = $ipAddress;
return $this;
}
public function getUserAgent(): ?string
{
return $this->userAgent;
}
public function setUserAgent(?string $userAgent): self
{
$this->userAgent = $userAgent;
return $this;
}
public function getFirstLogin(): \DateTime
{
return $this->firstLogin;
}
public function getLastActivity(): \DateTime
{
return $this->lastActivity;
}
public function setLastActivity(\DateTime $lastActivity): self
{
$this->lastActivity = $lastActivity;
return $this;
}
public function isActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getRefreshToken(): ?string
{
return $this->refreshToken;
}
public function setRefreshToken(?string $refreshToken): self
{
$this->refreshToken = $refreshToken;
return $this;
}
public function getLogoutReason(): ?string
{
return $this->logoutReason;
}
public function setLogoutReason(?string $logoutReason): self
{
$this->logoutReason = $logoutReason;
return $this;
}
public function getLogoutAt(): ?\DateTime
{
return $this->logoutAt;
}
public function setLogoutAt(?\DateTime $logoutAt): self
{
$this->logoutAt = $logoutAt;
return $this;
}
}