
#include "ItemFilters.h"
#include "Faye/Inventory/BookItem.h"
#include "Faye/Inventory/CoffeeItem.h"

bool UItemFilter::Pass(const UItem* Item) const
{
	if (!Item) return false;
	
	if (!ItemName.IsEmpty() && !Item->ItemName.CompareToCaseIgnored(ItemName))
		return false;
	
	if (ItemCategory != EItemCategory::None && Item->ItemCategory != ItemCategory)
		return false;
	
	if ((PriceStart > -1 && PriceEnd > -1) && (Item->Price < PriceStart || Item->Price > PriceEnd))
		return false;
	
	return true;
}

bool UBookFilter::Pass(const UItem* Item) const
{
	const UBookItem* Book = Cast<UBookItem>(Item);
	
	if (!UItemFilter::Pass(Item)) return false;
	
	if (BookCategory != EBookCategory::None && BookCategory != Book->BookCategory)
		return false;
	
	if (BookSubCategory != EBookSubCategory::None && BookSubCategory != Book->BookSubCategory)
		return false;
	
	if ((PublicationDateStart > -1 && PublicationDateEnd > -1) && (Book->PublicationDate < PublicationDateStart || Book->PublicationDate > PublicationDateEnd))
		return false;
	
	if (!Author.IsEmpty() && !Book->Author.CompareToCaseIgnored(Author))
		return false;
	
	if ((PageNumberStart > -1 && PageNumberEnd > -1) && (Book->PageNumber < PageNumberStart || Book->PageNumber > PageNumberEnd))
		return false;
	
	return true;
}

bool UCoffeeFilter::Pass(const UItem* Item) const
{
	const UCoffeeItem* CoffeeItem = Cast<UCoffeeItem>(Item);
	
	if (!Super::Pass(Item)) return false;
	
	if (CoffeeType != ECoffeeType::None && CoffeeType != CoffeeItem->CoffeeType)
		return false;
	
	if (CoffeeSize != ECoffeeSize::None && CoffeeSize != CoffeeItem->CoffeeSize)
		return false;
	
	if (CoffeeAddition != ECoffeeAddition::None && CoffeeAddition != CoffeeItem->CoffeeAddition)
		return false;
	
	if (bIced != CoffeeItem->bIced)
		return false;
	
	if (bWhippedCream != CoffeeItem->bWhippedCream)
		return false;
	
	return true;
}
