<?php

declare(strict_types=1);

namespace App\Entity;

use App\Enum\Orientation;
use App\Repository\DeviceRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: DeviceRepository::class)]
class Device
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 17, unique: true)]
    private string $mac = '';

    #[ORM\Column(length: 100)]
    private string $name = '';

    #[ORM\Column(enumType: Orientation::class)]
    private Orientation $orientation = Orientation::Landscape;

    /** Hours between rotation cycles. */
    #[ORM\Column]
    private int $rotationIntervalHours = 24;

    /** Number of display cycles before an image may repeat. */
    #[ORM\Column]
    private int $uniquenessWindow = 10;

    #[ORM\ManyToOne(inversedBy: 'devices')]
    #[ORM\JoinColumn(nullable: false)]
    private ?User $user = null;

    #[ORM\Column]
    private \DateTimeImmutable $linkedAt;

    public function __construct()
    {
        $this->linkedAt = new \DateTimeImmutable();
    }

    public function getId(): ?int { return $this->id; }

    public function getMac(): string { return $this->mac; }
    public function setMac(string $mac): static { $this->mac = strtoupper($mac); return $this; }

    public function getName(): string { return $this->name; }
    public function setName(string $name): static { $this->name = $name; return $this; }

    public function getOrientation(): Orientation { return $this->orientation; }
    public function setOrientation(Orientation $orientation): static { $this->orientation = $orientation; return $this; }

    public function getRotationIntervalHours(): int { return $this->rotationIntervalHours; }
    public function setRotationIntervalHours(int $h): static { $this->rotationIntervalHours = $h; return $this; }

    public function getUniquenessWindow(): int { return $this->uniquenessWindow; }
    public function setUniquenessWindow(int $w): static { $this->uniquenessWindow = $w; return $this; }

    public function getUser(): ?User { return $this->user; }
    public function setUser(?User $user): static { $this->user = $user; return $this; }

    public function getLinkedAt(): \DateTimeImmutable { return $this->linkedAt; }
    public function setLinkedAt(\DateTimeImmutable $dt): static { $this->linkedAt = $dt; return $this; }
}
