package speiger.src.coreengine.assets.api;

import java.util.Map;

public record AssetFilter(String prefix, String extension) {
	public static AssetFilter json(String prefix) {
		return new AssetFilter(prefix, ".json");
	}
	
	public ID id(ID file) {
		String location = file.fileLocation();
		return ID.of(file.domain(), location.substring(prefix().length()+1, location.length()-extension().length()));
	}
	
	public ID file(ID id) {
		return ID.of(id.domain(), prefix()+"/"+id.fileLocation()+extension());
	}
	
	public Map<ID, IAsset> list(IAssetProvider provider) { 
		return provider.list(prefix, T -> T.endsWith(extension)); 
	}
	
	public Map<ID, IAsset> listRoot(IAssetProvider provider) { 
		return provider.list(prefix, T -> T.endsWith(extension) && T.isRootFolder(prefix));
	}
	
	public Map<ID, MultiAsset> multi(IAssetProvider provider) {
		return provider.listAll(prefix, T -> T.endsWith(extension));
	}
	
	public Map<ID, MultiAsset> multiRoot(IAssetProvider provider) {
		return provider.listAll(prefix, T -> T.endsWith(extension) && T.isRootFolder(prefix));
	}
	
}
