package p.packer.models;

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

public record PackerWorkspaceCacheState(
        int schemaVersion,
        List<PackerAssetCacheEntry> assets) {
    public static final int CURRENT_SCHEMA_VERSION = 1;
    public static final PackerWorkspaceCacheState EMPTY = new PackerWorkspaceCacheState(CURRENT_SCHEMA_VERSION, List.of());

    public PackerWorkspaceCacheState {
        if (schemaVersion <= 0) {
            throw new IllegalArgumentException("schemaVersion must be positive");
        }
        assets = List.copyOf(Objects.requireNonNull(assets, "assets"));
    }

    public Optional<PackerAssetCacheEntry> findAsset(int assetId) {
        return assets.stream()
                .filter(asset -> asset.assetId() == assetId)
                .findFirst();
    }
}
