package ar.com.companeros.decision; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; /** Datos copiados y acotados; nunca una entidad viva ni el mapa entero del servidor. */ public record ObservationSnapshot(UUID worldId, String dimension, int x, int y, int z, float health, int hunger, Map inventory, String currentGoal, List observations, List memories, List untrustedMessages) { public ObservationSnapshot { Objects.requireNonNull(worldId); Objects.requireNonNull(dimension); Objects.requireNonNull(currentGoal); inventory = Map.copyOf(inventory); observations = List.copyOf(observations); memories = List.copyOf(memories); untrustedMessages = List.copyOf(untrustedMessages); if (dimension.length() > 128 || currentGoal.length() > 512 || !Float.isFinite(health) || health < 0 || hunger < 0 || hunger > 20 || inventory.size() > 128 || inventory.entrySet().stream().anyMatch(e -> e.getKey().length() > 128 || e.getValue() < 0)) throw new IllegalArgumentException("Estado observado fuera de límite"); bound(observations, 32, 512); bound(memories, 16, 2048); bound(untrustedMessages, 16, 2304); } private static void bound(List values, int size, int chars) { if (values.size() > size || values.stream().anyMatch(value -> value.length() > chars)) throw new IllegalArgumentException("Observación textual fuera de límite"); } }