package p.packer.messages.assets;

import java.util.List;
import java.util.Objects;

public record ScenePackLayerRequest(
        boolean active,
        int glyphAssetId,
        int tileSize,
        float parallaxFactorX,
        float parallaxFactorY,
        int width,
        int height,
        List<ScenePackTileRequest> tiles) {

    public ScenePackLayerRequest {
        tiles = List.copyOf(Objects.requireNonNull(tiles, "tiles"));
        if (glyphAssetId < 0) {
            throw new IllegalArgumentException("glyphAssetId must be non-negative");
        }
        if (tileSize < 0) {
            throw new IllegalArgumentException("tileSize must be non-negative");
        }
        if (width <= 0 || height <= 0) {
            throw new IllegalArgumentException("width and height must be positive");
        }
        if (!Float.isFinite(parallaxFactorX) || parallaxFactorX < 0.0f) {
            throw new IllegalArgumentException("parallaxFactorX must be finite and non-negative");
        }
        if (!Float.isFinite(parallaxFactorY) || parallaxFactorY < 0.0f) {
            throw new IllegalArgumentException("parallaxFactorY must be finite and non-negative");
        }
        if (tiles.size() != width * height) {
            throw new IllegalArgumentException("tiles size must match width * height");
        }
    }
}
