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

import de.effigenix.domain.inventory.StockMovement;
import io.swagger.v3.oas.annotations.media.Schema;

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

@Schema(requiredProperties = {"id", "stockId", "articleId", "stockBatchId", "batchId", "batchType",
        "movementType", "direction", "quantityAmount", "quantityUnit", "performedBy", "performedAt"})
public record StockMovementResponse(
        String id,
        String stockId,
        String articleId,
        String stockBatchId,
        String batchId,
        String batchType,
        String movementType,
        String direction,
        BigDecimal quantityAmount,
        String quantityUnit,
        @Schema(nullable = true) String reason,
        @Schema(nullable = true) String referenceDocumentId,
        String performedBy,
        Instant performedAt
) {

    public static StockMovementResponse from(StockMovement movement) {
        return new StockMovementResponse(
                movement.id().value(),
                movement.stockId().value(),
                movement.articleId().value(),
                movement.stockBatchId().value(),
                movement.batchReference().batchId(),
                movement.batchReference().batchType().name(),
                movement.movementType().name(),
                movement.direction().name(),
                movement.quantity().amount(),
                movement.quantity().uom().name(),
                movement.reason(),
                movement.referenceDocumentId(),
                movement.performedBy(),
                movement.performedAt()
        );
    }
}
