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

import de.effigenix.domain.production.Ingredient;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(requiredProperties = {"id", "position", "articleId", "quantity", "uom", "substitutable"})
public record IngredientResponse(
        String id,
        int position,
        String articleId,
        String quantity,
        String uom,
        @Schema(nullable = true) String subRecipeId,
        boolean substitutable
) {
    public static IngredientResponse from(Ingredient ingredient) {
        return new IngredientResponse(
                ingredient.id().value(),
                ingredient.position(),
                ingredient.articleId(),
                ingredient.quantity().amount().toPlainString(),
                ingredient.quantity().uom().name(),
                ingredient.subRecipeId(),
                ingredient.substitutable()
        );
    }
}
