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

import de.effigenix.domain.masterdata.article.Article;
import de.effigenix.domain.masterdata.supplier.SupplierId;
import io.swagger.v3.oas.annotations.media.Schema;

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

@Schema(requiredProperties = {"id", "name", "articleNumber", "categoryId", "salesUnits", "status", "supplierIds", "createdAt", "updatedAt"})
public record ArticleResponse(
        String id,
        String name,
        String articleNumber,
        String categoryId,
        List<SalesUnitResponse> salesUnits,
        String status,
        List<String> supplierIds,
        OffsetDateTime createdAt,
        OffsetDateTime updatedAt
) {
    public static ArticleResponse from(Article article) {
        return new ArticleResponse(
                article.id().value(),
                article.name().value(),
                article.articleNumber().value(),
                article.categoryId().value(),
                article.salesUnits().stream().map(SalesUnitResponse::from).toList(),
                article.status().name(),
                article.supplierReferences().stream().map(SupplierId::value).toList(),
                article.createdAt(),
                article.updatedAt()
        );
    }
}
