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

import de.effigenix.domain.production.TracedBatch;

import java.util.List;

public record TraceBatchForwardResponse(
        String originBatchId,
        List<TracedBatchResponse> tracedBatches,
        int totalCount
) {
    public record TracedBatchResponse(
            String id,
            String batchNumber,
            String recipeId,
            String status,
            int depth
    ) {
        public static TracedBatchResponse from(TracedBatch traced) {
            var batch = traced.batch();
            return new TracedBatchResponse(
                    batch.id().value(),
                    batch.batchNumber().value(),
                    batch.recipeId().value(),
                    batch.status().name(),
                    traced.depth()
            );
        }
    }

    public static TraceBatchForwardResponse from(String originBatchId, List<TracedBatch> tracedBatches) {
        var responses = tracedBatches.stream()
                .map(TracedBatchResponse::from)
                .toList();
        return new TraceBatchForwardResponse(originBatchId, responses, responses.size());
    }
}
