<?php

declare(strict_types=1);

namespace App\ValueObject;

use App\Entity\InventoryRecord;
use App\Enum\StockState;

final readonly class DrinkStock
{
    public function __construct(
        public InventoryRecord $record,
        public StockState $stock,
    ) {}

    public static function fromInventoryRecord(InventoryRecord $record, float $lowStockMultiplier): self
    {
        if ($record->getQuantity() === 0 && $record->getDrinkType()->getDesiredStock() > 0) {
            return new self($record, StockState::CRITICAL);
        }
        if ($record->getQuantity() < ($record->getDrinkType()->getDesiredStock() * $lowStockMultiplier)) {
            return new self($record, StockState::LOW);
        }
        if ($record->getQuantity() > $record->getDrinkType()->getDesiredStock()) {
            return new self($record, StockState::HIGH);
        }

        return new self($record, StockState::NORMAL);
    }
}
