<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\DeviceRepository;
use DateTime;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\PrePersist;
use Doctrine\ORM\Mapping\PreUpdate;
use Symfony\Component\Uid\Uuid;
#[Entity(DeviceRepository::class)]
#[HasLifecycleCallbacks]
class Device
{
#[Id]
#[ManyToOne(targetEntity: Creator::class, inversedBy: 'devices')]
#[JoinColumn(name: 'creator_id', onDelete: 'CASCADE')]
private Creator $creator;
#[Id]
#[Column(type: 'uuid', name: 'device_id')]
private Uuid $deviceId;
#[Column(type: 'text', nullable: true)]
private ?string $pushToken;
#[Column(type: 'string', length: 50)]
private string $platform;
#[Column(type: 'string', length: 50)]
private string $appVersion;
#[Column(type: 'string', length: 50)]
private string $timezone;
#[Column('created_at', 'datetime')]
private DateTime $createdAt;
#[Column('updated_at', 'datetime', nullable: true)]
private ?DateTime $updatedAt = null;
public function __construct(
Creator $creator,
Uuid $deviceId,
?string $pushToken,
string $platform,
string $appVersion,
string $timezone,
) {
$this->creator = $creator;
$this->deviceId = $deviceId;
$this->pushToken = $pushToken;
$this->platform = $platform;
$this->appVersion = $appVersion;
$this->timezone = $timezone;
}
#[PrePersist]
public function prePersist(): void
{
$this->createdAt = new DateTime();
}
#[PreUpdate]
public function preUpdate(): void
{
$this->updatedAt = new DateTime();
}
public function getId(): Uuid
{
return $this->deviceId;
}
public function getDeviceId(): Uuid
{
return $this->deviceId;
}
public function getPushToken(): ?string
{
return $this->pushToken;
}
public function getPlatform(): string
{
return $this->platform;
}
public function getAppVersion(): string
{
return $this->appVersion;
}
public function getTimezone(): string
{
return $this->timezone;
}
public function getCreator(): Creator
{
return $this->creator;
}
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
public function getUpdatedAt(): ?DateTime
{
return $this->updatedAt;
}
public function hasPushToken(): bool
{
return $this->pushToken !== null && $this->pushToken !== '';
}
public function setPushToken(?string $pushToken): void
{
$this->pushToken = $pushToken;
}
public function setPlatform(string $platform): void
{
$this->platform = $platform;
}
public function setAppVersion(string $appVersion): void
{
$this->appVersion = $appVersion;
}
public function setTimezone(string $timezone): void
{
$this->timezone = $timezone;
}
}