package io.github.Cnly.WowSuchCleaner.WowSuchCleaner.config.auction;

import io.github.Cnly.Crafter.Crafter.utils.ItemUtils;

import java.util.Map;

import org.bukkit.inventory.ItemStack;

public class AuctionableItem
{
    
    private final ItemStack item;
    private final double startingPrice;
    private final double minimumIncrement;
    private final int preserveTimeInSeconds;
    private final int auctionDurationInSeconds;
    
    @SuppressWarnings("unchecked")
    public static AuctionableItem fromMap(Map<?, ?> map)
    {
        
        Map<String, Object> convertedMap = (Map<String, Object>)map;
        
        Object itemRepresent = convertedMap.get("item");
        ItemStack item = ItemUtils.getItemByIdString((String)itemRepresent);
        
        double startingPrice = (double)convertedMap.get("startingPrice");
        double minimumIncrement = (double)convertedMap.get("minimumIncrement");
        int preserveTimeInSeconds = (int)convertedMap.get("preserveTimeInSeconds");
        int auctionDurationInSeconds = (int)convertedMap.get("auctionDurationInSeconds");
        
        return new AuctionableItem(item, startingPrice, minimumIncrement, preserveTimeInSeconds, auctionDurationInSeconds);
    }

    public AuctionableItem(ItemStack item, double startingPrice, double minimumIncrement, int preserveTimeInSeconds, int auctionDurationInSeconds)
    {
        super();
        this.item = item;
        this.startingPrice = startingPrice;
        this.minimumIncrement = minimumIncrement;
        this.preserveTimeInSeconds = preserveTimeInSeconds;
        this.auctionDurationInSeconds = auctionDurationInSeconds;
    }
    
    public boolean isTheSameItem(ItemStack item)
    {
        return this.item.isSimilar(item);
    }
    
    public ItemStack getItem()
    {
        return item;
    }

    public double getStartingPrice()
    {
        return startingPrice;
    }

    public double getMinimumIncrement()
    {
        return minimumIncrement;
    }

    public int getPreserveTimeInSeconds()
    {
        return preserveTimeInSeconds;
    }

    public int getAuctionDurationInSeconds()
    {
        return auctionDurationInSeconds;
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + auctionDurationInSeconds;
        result = prime * result + ((item == null) ? 0 : item.hashCode());
        long temp;
        temp = Double.doubleToLongBits(minimumIncrement);
        result = prime * result + (int)(temp ^ (temp >>> 32));
        result = prime * result + preserveTimeInSeconds;
        temp = Double.doubleToLongBits(startingPrice);
        result = prime * result + (int)(temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if(this == obj)
            return true;
        if(obj == null)
            return false;
        if(getClass() != obj.getClass())
            return false;
        AuctionableItem other = (AuctionableItem)obj;
        if(auctionDurationInSeconds != other.auctionDurationInSeconds)
            return false;
        if(item == null)
        {
            if(other.item != null)
                return false;
        }
        else if(!item.equals(other.item))
            return false;
        if(Double.doubleToLongBits(minimumIncrement) != Double.doubleToLongBits(other.minimumIncrement))
            return false;
        if(preserveTimeInSeconds != other.preserveTimeInSeconds)
            return false;
        if(Double.doubleToLongBits(startingPrice) != Double.doubleToLongBits(other.startingPrice))
            return false;
        return true;
    }
    
}

@@ -1723,40 +1723,159 @@
     
-return this.item.isSimilar(item)
+if(item.getType() != this.item.getType()) return false;%0A        if(item.getDurability() != this.item.getDurability()) return false;%0A        return true
 ;%0A  

Support items with enchantments, etc.