// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.inventory;

import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
import com.hypixel.hytale.protocol.ItemResourceType;
import com.hypixel.hytale.server.core.asset.type.item.config.Item;
import javax.annotation.Nonnull;
import java.util.Objects;

public class ResourceQuantity
{
    protected String resourceId;
    protected int quantity;
    
    public ResourceQuantity(final String resourceId, final int quantity) {
        Objects.requireNonNull(resourceId, "resourceId cannot be null!");
        if (quantity <= 0) {
            throw new IllegalArgumentException("quantity " + quantity + " must be >0!");
        }
        this.resourceId = resourceId;
        this.quantity = quantity;
    }
    
    protected ResourceQuantity() {
    }
    
    public String getResourceId() {
        return this.resourceId;
    }
    
    public int getQuantity() {
        return this.quantity;
    }
    
    @Nonnull
    public ResourceQuantity clone(final int quantity) {
        return new ResourceQuantity(this.resourceId, quantity);
    }
    
    @Nullable
    public ItemResourceType getResourceType(@Nonnull final Item item) {
        return ItemContainer.getMatchingResourceType(item, this.resourceId);
    }
    
    @Override
    public boolean equals(@Nullable final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final ResourceQuantity itemStack = (ResourceQuantity)o;
        return this.quantity == itemStack.quantity && ((this.resourceId != null) ? this.resourceId.equals(itemStack.resourceId) : (itemStack.resourceId == null));
    }
    
    @Override
    public int hashCode() {
        int result = (this.resourceId != null) ? this.resourceId.hashCode() : 0;
        result = 31 * result + this.quantity;
        return result;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "ResourceQuantity{resourceId='" + this.resourceId + "', quantity=" + this.quantity;
    }
}
