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

import de.effigenix.domain.inventory.Reservation;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.List;

public record ReservationResponse(
        String id,
        String referenceType,
        String referenceId,
        BigDecimal quantityAmount,
        String quantityUnit,
        String priority,
        Instant reservedAt,
        List<StockBatchAllocationResponse> allocations
) {

    public static ReservationResponse from(Reservation reservation) {
        return new ReservationResponse(
                reservation.id().value(),
                reservation.referenceType().name(),
                reservation.referenceId(),
                reservation.quantity().amount(),
                reservation.quantity().uom().name(),
                reservation.priority().name(),
                reservation.reservedAt(),
                reservation.allocations().stream()
                        .map(StockBatchAllocationResponse::from)
                        .toList()
        );
    }
}
