<?php

declare(strict_types=1);

namespace App\Entity;

use App\Repository\InventoryRecordRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: InventoryRecordRepository::class)]
#[ORM\Table(name: 'inventory_record')]
class InventoryRecord
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private null|int $id = null;

    public function __construct(
        #[ORM\ManyToOne(targetEntity: DrinkType::class, inversedBy: 'inventoryRecords')]
        #[ORM\JoinColumn(name: 'drink_type_id', referencedColumnName: 'id', nullable: false)]
        private DrinkType $drinkType,
        #[ORM\Column(type: 'integer')]
        private int $quantity,
        #[ORM\Column(type: 'datetime_immutable')]
        private DateTimeImmutable $timestamp = new DateTimeImmutable(),
        #[ORM\Column(type: 'datetime_immutable')]
        private DateTimeImmutable $createdAt = new DateTimeImmutable(),
        #[ORM\Column(type: 'datetime_immutable')]
        private DateTimeImmutable $updatedAt = new DateTimeImmutable(),
    ) {}

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

    public function getDrinkType(): DrinkType
    {
        return $this->drinkType;
    }

    public function setDrinkType(DrinkType $drinkType): self
    {
        $this->drinkType = $drinkType;
        $this->updateTimestamp();
        return $this;
    }

    public function getQuantity(): int
    {
        return $this->quantity;
    }

    public function setQuantity(int $quantity): self
    {
        $this->quantity = $quantity;
        $this->updateTimestamp();
        return $this;
    }

    public function getTimestamp(): DateTimeImmutable
    {
        return $this->timestamp;
    }

    public function setTimestamp(DateTimeImmutable $timestamp): self
    {
        $this->timestamp = $timestamp;
        $this->updateTimestamp();
        return $this;
    }

    public function getCreatedAt(): DateTimeImmutable
    {
        return $this->createdAt;
    }

    public function getUpdatedAt(): DateTimeImmutable
    {
        return $this->updatedAt;
    }

    private function updateTimestamp(): void
    {
        $this->updatedAt = new DateTimeImmutable();
    }
}
