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

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

import java.time.OffsetDateTime;
import java.util.List;

@Schema(requiredProperties = {"id", "name", "version", "type", "description", "yieldPercentage", "outputQuantity", "outputUom", "articleId", "status", "ingredients", "productionSteps", "createdAt", "updatedAt"})
public record RecipeResponse(
        String id,
        String name,
        int version,
        String type,
        String description,
        int yieldPercentage,
        @Schema(nullable = true) Integer shelfLifeDays,
        String outputQuantity,
        String outputUom,
        String articleId,
        String status,
        List<IngredientResponse> ingredients,
        List<ProductionStepResponse> productionSteps,
        OffsetDateTime createdAt,
        OffsetDateTime updatedAt
) {
    public static RecipeResponse from(Recipe recipe) {
        return new RecipeResponse(
                recipe.id().value(),
                recipe.name().value(),
                recipe.version(),
                recipe.type().name(),
                recipe.description(),
                recipe.yieldPercentage().value(),
                recipe.shelfLifeDays(),
                recipe.outputQuantity().amount().toPlainString(),
                recipe.outputQuantity().uom().name(),
                recipe.articleId(),
                recipe.status().name(),
                recipe.ingredients().stream().map(IngredientResponse::from).toList(),
                recipe.productionSteps().stream().map(ProductionStepResponse::from).toList(),
                recipe.createdAt(),
                recipe.updatedAt()
        );
    }
}
