<?php

declare(strict_types=1);

namespace App\Entity;

use App\Repository\DeviceImageHistoryRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: DeviceImageHistoryRepository::class)]
#[ORM\Index(columns: ['device_id', 'served_at'], name: 'idx_history_device_served')]
class DeviceImageHistory
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Device $device;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Image $image;

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

    public function __construct(Device $device, Image $image)
    {
        $this->device   = $device;
        $this->image    = $image;
        $this->servedAt = new \DateTimeImmutable();
    }

    public function getId(): ?int { return $this->id; }
    public function getDevice(): Device { return $this->device; }
    public function getImage(): Image { return $this->image; }
    public function getServedAt(): \DateTimeImmutable { return $this->servedAt; }
}
