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

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

import java.math.BigDecimal;

@Schema(requiredProperties = {"id", "name", "storageType", "active"})
public record StorageLocationResponse(
        String id,
        String name,
        String storageType,
        @Schema(nullable = true) TemperatureRangeResponse temperatureRange,
        boolean active
) {

    public static StorageLocationResponse from(StorageLocation location) {
        TemperatureRangeResponse tempRange = null;
        if (location.temperatureRange() != null) {
            tempRange = new TemperatureRangeResponse(
                    location.temperatureRange().minTemperature(),
                    location.temperatureRange().maxTemperature()
            );
        }

        return new StorageLocationResponse(
                location.id().value(),
                location.name().value(),
                location.storageType().name(),
                tempRange,
                location.active()
        );
    }

    @Schema(requiredProperties = {"minTemperature", "maxTemperature"})
    public record TemperatureRangeResponse(BigDecimal minTemperature, BigDecimal maxTemperature) {}
}
