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;

@Schema(requiredProperties = {"id", "name", "version", "type", "description", "yieldPercentage", "outputQuantity", "outputUom", "articleId", "status", "ingredientCount", "stepCount", "createdAt", "updatedAt"})
public record RecipeSummaryResponse(
        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,
        int ingredientCount,
        int stepCount,
        OffsetDateTime createdAt,
        OffsetDateTime updatedAt
) {
    public static RecipeSummaryResponse from(Recipe recipe) {
        return new RecipeSummaryResponse(
                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().size(),
                recipe.productionSteps().size(),
                recipe.createdAt(),
                recipe.updatedAt()
        );
    }
}
