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

import de.effigenix.domain.masterdata.customer.FrameContract;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDate;
import java.util.List;

@Schema(requiredProperties = {"id", "validFrom", "validUntil", "deliveryRhythm", "lineItems"})
public record FrameContractResponse(
        String id,
        LocalDate validFrom,
        LocalDate validUntil,
        String deliveryRhythm,
        List<ContractLineItemResponse> lineItems
) {
    public static FrameContractResponse from(FrameContract fc) {
        if (fc == null) return null;
        return new FrameContractResponse(
                fc.id().value(),
                fc.validFrom(),
                fc.validUntil(),
                fc.deliveryRhythm().name(),
                fc.lineItems().stream().map(ContractLineItemResponse::from).toList()
        );
    }
}
