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

import de.effigenix.domain.masterdata.supplier.Supplier;
import io.swagger.v3.oas.annotations.media.Schema;

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

@Schema(requiredProperties = {"id", "name", "contactInfo", "certificates", "status", "createdAt", "updatedAt"})
public record SupplierResponse(
        String id,
        String name,
        @Schema(nullable = true) AddressResponse address,
        ContactInfoResponse contactInfo,
        @Schema(nullable = true) PaymentTermsResponse paymentTerms,
        List<QualityCertificateResponse> certificates,
        @Schema(nullable = true) SupplierRatingResponse rating,
        String status,
        OffsetDateTime createdAt,
        OffsetDateTime updatedAt
) {
    public static SupplierResponse from(Supplier supplier) {
        return new SupplierResponse(
                supplier.id().value(),
                supplier.name().value(),
                AddressResponse.from(supplier.address()),
                ContactInfoResponse.from(supplier.contactInfo()),
                PaymentTermsResponse.from(supplier.paymentTerms()),
                supplier.certificates().stream().map(QualityCertificateResponse::from).toList(),
                SupplierRatingResponse.from(supplier.rating()),
                supplier.status().name(),
                supplier.createdAt(),
                supplier.updatedAt()
        );
    }
}
