package ru.dbotthepony.kstarbound.defs.actor.player

import com.google.common.collect.ImmutableSet
import ru.dbotthepony.kstarbound.json.builder.JsonFactory
import ru.dbotthepony.kstarbound.item.ItemStack
import java.util.function.Predicate

@JsonFactory
data class BagFilterConfig(
	val typeBlacklist: ImmutableSet<String>? = null,
	val typeWhitelist: ImmutableSet<String>? = null,
	val tagBlacklist: ImmutableSet<String>? = null,
	val categoryBlacklist: ImmutableSet<String>? = null,
) : Predicate<ItemStack> {
	override fun test(t: ItemStack): Boolean {
		if (t.isEmpty)
			return false

		if (typeBlacklist != null) {
			return !typeBlacklist.contains(t.category)
		} else if (typeWhitelist != null) {
			return typeWhitelist.contains(t.category)
		}

		return true
	}
}
