package de.effigenix.infrastructure.inventory.web.dto;

import de.effigenix.domain.inventory.Stock;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(requiredProperties = {"id", "articleId", "storageLocationId"})
public record CreateStockResponse(
        String id,
        String articleId,
        String storageLocationId,
        @Schema(nullable = true) MinimumLevelResponse minimumLevel,
        @Schema(nullable = true) Integer minimumShelfLifeDays
) {

    public static CreateStockResponse from(Stock stock) {
        MinimumLevelResponse minimumLevel = null;
        if (stock.minimumLevel() != null) {
            minimumLevel = new MinimumLevelResponse(
                    stock.minimumLevel().quantity().amount(),
                    stock.minimumLevel().quantity().uom().name()
            );
        }

        Integer shelfLifeDays = null;
        if (stock.minimumShelfLife() != null) {
            shelfLifeDays = stock.minimumShelfLife().days();
        }

        return new CreateStockResponse(
                stock.id().value(),
                stock.articleId().value(),
                stock.storageLocationId().value(),
                minimumLevel,
                shelfLifeDays
        );
    }
}
