<?php

namespace App\Auth\Entity;

use Doctrine\ORM\Mapping as ORM;

use App\Auth\Repository\UserActiveContextRepository;
#[ORM\Entity(repositoryClass: UserActiveContextRepository::class)]
#[ORM\Table(name: 'user_active_context')]
class UserActiveContext
{
    #[ORM\Id]
    #[ORM\OneToOne(targetEntity: User::class)]
    #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    private User $user;

    #[ORM\Column(name: 'db_uuid', type: 'string', length: 36)]
    private string $dbUuid;

    #[ORM\Column(name: 'updated_at', type: 'integer')]
    private int $updatedAt;

    public function __construct(User $user, string $dbUuid)
    {
        $this->user      = $user;
        $this->dbUuid    = $dbUuid;
        $this->updatedAt = time();
    }

    public function getUser(): User    { return $this->user; }
    public function getDbUuid(): string { return $this->dbUuid; }
    public function getUpdatedAt(): int { return $this->updatedAt; }

    public function setDbUuid(string $dbUuid): self
    {
        $this->dbUuid    = $dbUuid;
        $this->updatedAt = time();
        return $this;
    }
}
