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

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

import com.hypixel.hytale.assetstore.AssetRegistry;
import com.hypixel.hytale.codec.ExtraInfo;
import javax.annotation.Nonnull;
import org.bson.BsonDocument;
import javax.annotation.Nullable;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.core.io.NetworkSerializable;

public class MaterialQuantity implements NetworkSerializable<com.hypixel.hytale.protocol.MaterialQuantity>
{
    public static final MaterialQuantity[] EMPTY_ARRAY;
    public static final BuilderCodec<MaterialQuantity> CODEC;
    @Nullable
    protected String itemId;
    @Nullable
    protected String resourceTypeId;
    protected String tag;
    protected int tagIndex;
    protected int quantity;
    @Nullable
    protected BsonDocument metadata;
    
    public MaterialQuantity(@Nullable final String itemId, @Nullable final String resourceTypeId, @Nullable final String tag, final int quantity, final BsonDocument metadata) {
        this.tagIndex = Integer.MIN_VALUE;
        this.quantity = 1;
        if (itemId == null && resourceTypeId == null && tag == null) {
            throw new IllegalArgumentException("itemId, resourceTypeId and tag cannot all be null!");
        }
        if (quantity <= 0) {
            throw new IllegalArgumentException("quantity " + quantity + " must be >0!");
        }
        this.itemId = itemId;
        this.resourceTypeId = resourceTypeId;
        this.tag = tag;
        this.quantity = quantity;
        this.metadata = metadata;
    }
    
    protected MaterialQuantity() {
        this.tagIndex = Integer.MIN_VALUE;
        this.quantity = 1;
    }
    
    @Nullable
    public String getItemId() {
        return this.itemId;
    }
    
    @Nullable
    public String getResourceTypeId() {
        return this.resourceTypeId;
    }
    
    public int getTagIndex() {
        return this.tagIndex;
    }
    
    public int getQuantity() {
        return this.quantity;
    }
    
    public BsonDocument getMetadata() {
        return this.metadata;
    }
    
    @Nonnull
    public MaterialQuantity clone(final int quantity) {
        return new MaterialQuantity(this.itemId, this.resourceTypeId, this.tag, quantity, this.metadata);
    }
    
    @Nullable
    public ItemStack toItemStack() {
        if (this.itemId == null) {
            return null;
        }
        if (this.itemId.equals("Empty")) {
            return ItemStack.EMPTY;
        }
        return new ItemStack(this.itemId, this.quantity, this.metadata);
    }
    
    @Nullable
    public ResourceQuantity toResource() {
        if (this.resourceTypeId == null) {
            return null;
        }
        return new ResourceQuantity(this.resourceTypeId, this.quantity);
    }
    
    @Nonnull
    @Override
    public com.hypixel.hytale.protocol.MaterialQuantity toPacket() {
        final com.hypixel.hytale.protocol.MaterialQuantity packet = new com.hypixel.hytale.protocol.MaterialQuantity();
        if (this.itemId != null) {
            packet.itemId = this.itemId.toString();
        }
        packet.itemTag = this.tagIndex;
        packet.resourceTypeId = this.resourceTypeId;
        packet.quantity = this.quantity;
        return packet;
    }
    
    @Override
    public boolean equals(@Nullable final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final MaterialQuantity that = (MaterialQuantity)o;
        if (this.quantity != that.quantity) {
            return false;
        }
        Label_0075: {
            if (this.itemId != null) {
                if (this.itemId.equals(that.itemId)) {
                    break Label_0075;
                }
            }
            else if (that.itemId == null) {
                break Label_0075;
            }
            return false;
        }
        Label_0108: {
            if (this.resourceTypeId != null) {
                if (this.resourceTypeId.equals(that.resourceTypeId)) {
                    break Label_0108;
                }
            }
            else if (that.resourceTypeId == null) {
                break Label_0108;
            }
            return false;
        }
        if (this.tag != null) {
            if (this.tag.equals(that.tag)) {
                return (this.metadata != null) ? this.metadata.equals(that.metadata) : (that.metadata == null);
            }
        }
        else if (that.tag == null) {
            return (this.metadata != null) ? this.metadata.equals(that.metadata) : (that.metadata == null);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        int result = (this.itemId != null) ? this.itemId.hashCode() : 0;
        result = 31 * result + ((this.resourceTypeId != null) ? this.resourceTypeId.hashCode() : 0);
        result = 31 * result + ((this.tag != null) ? this.tag.hashCode() : 0);
        result = 31 * result + this.quantity;
        result = 31 * result + ((this.metadata != null) ? this.metadata.hashCode() : 0);
        return result;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "MaterialQuantity{itemId=" + this.itemId + ", resourceTypeId='" + this.resourceTypeId + "', tag='" + this.tag + "', quantity=" + this.quantity + ", metadata=" + String.valueOf(this.metadata);
    }
    
    static {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     1: anewarray       Lcom/hypixel/hytale/server/core/inventory/MaterialQuantity;
        //     4: putstatic       com/hypixel/hytale/server/core/inventory/MaterialQuantity.EMPTY_ARRAY:[Lcom/hypixel/hytale/server/core/inventory/MaterialQuantity;
        //     7: ldc             Lcom/hypixel/hytale/server/core/inventory/MaterialQuantity;.class
        //     9: invokedynamic   BootstrapMethod #2, get:()Ljava/util/function/Supplier;
        //    14: invokestatic    com/hypixel/hytale/codec/builder/BuilderCodec.builder:(Ljava/lang/Class;Ljava/util/function/Supplier;)Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //    17: new             Lcom/hypixel/hytale/codec/KeyedCodec;
        //    20: dup            
        //    21: ldc             "ItemId"
        //    23: getstatic       com/hypixel/hytale/codec/Codec.STRING:Lcom/hypixel/hytale/codec/codecs/simple/StringCodec;
        //    26: invokespecial   com/hypixel/hytale/codec/KeyedCodec.<init>:(Ljava/lang/String;Lcom/hypixel/hytale/codec/Codec;)V
        //    29: invokedynamic   BootstrapMethod #3, accept:()Ljava/util/function/BiConsumer;
        //    34: invokedynamic   BootstrapMethod #4, apply:()Ljava/util/function/Function;
        //    39: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.addField:(Lcom/hypixel/hytale/codec/KeyedCodec;Ljava/util/function/BiConsumer;Ljava/util/function/Function;)Lcom/hypixel/hytale/codec/builder/BuilderCodec$BuilderBase;
        //    42: checkcast       Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //    45: new             Lcom/hypixel/hytale/codec/KeyedCodec;
        //    48: dup            
        //    49: ldc             "ResourceTypeId"
        //    51: getstatic       com/hypixel/hytale/codec/Codec.STRING:Lcom/hypixel/hytale/codec/codecs/simple/StringCodec;
        //    54: invokespecial   com/hypixel/hytale/codec/KeyedCodec.<init>:(Ljava/lang/String;Lcom/hypixel/hytale/codec/Codec;)V
        //    57: invokedynamic   BootstrapMethod #5, accept:()Ljava/util/function/BiConsumer;
        //    62: invokedynamic   BootstrapMethod #6, apply:()Ljava/util/function/Function;
        //    67: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.addField:(Lcom/hypixel/hytale/codec/KeyedCodec;Ljava/util/function/BiConsumer;Ljava/util/function/Function;)Lcom/hypixel/hytale/codec/builder/BuilderCodec$BuilderBase;
        //    70: checkcast       Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //    73: new             Lcom/hypixel/hytale/codec/KeyedCodec;
        //    76: dup            
        //    77: ldc             "ItemTag"
        //    79: getstatic       com/hypixel/hytale/codec/Codec.STRING:Lcom/hypixel/hytale/codec/codecs/simple/StringCodec;
        //    82: invokespecial   com/hypixel/hytale/codec/KeyedCodec.<init>:(Ljava/lang/String;Lcom/hypixel/hytale/codec/Codec;)V
        //    85: invokedynamic   BootstrapMethod #7, accept:()Ljava/util/function/BiConsumer;
        //    90: invokedynamic   BootstrapMethod #8, apply:()Ljava/util/function/Function;
        //    95: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.addField:(Lcom/hypixel/hytale/codec/KeyedCodec;Ljava/util/function/BiConsumer;Ljava/util/function/Function;)Lcom/hypixel/hytale/codec/builder/BuilderCodec$BuilderBase;
        //    98: checkcast       Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //   101: new             Lcom/hypixel/hytale/codec/KeyedCodec;
        //   104: dup            
        //   105: ldc             "Quantity"
        //   107: getstatic       com/hypixel/hytale/codec/Codec.INTEGER:Lcom/hypixel/hytale/codec/codecs/simple/IntegerCodec;
        //   110: invokespecial   com/hypixel/hytale/codec/KeyedCodec.<init>:(Ljava/lang/String;Lcom/hypixel/hytale/codec/Codec;)V
        //   113: invokedynamic   BootstrapMethod #9, accept:()Ljava/util/function/BiConsumer;
        //   118: invokedynamic   BootstrapMethod #10, apply:()Ljava/util/function/Function;
        //   123: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.append:(Lcom/hypixel/hytale/codec/KeyedCodec;Ljava/util/function/BiConsumer;Ljava/util/function/Function;)Lcom/hypixel/hytale/codec/builder/BuilderField$FieldBuilder;
        //   126: iconst_0       
        //   127: invokestatic    java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
        //   130: invokestatic    com/hypixel/hytale/codec/validation/Validators.greaterThan:(Ljava/lang/Comparable;)Lcom/hypixel/hytale/codec/validation/Validator;
        //   133: invokevirtual   com/hypixel/hytale/codec/builder/BuilderField$FieldBuilder.addValidator:(Lcom/hypixel/hytale/codec/validation/Validator;)Lcom/hypixel/hytale/codec/builder/BuilderField$FieldBuilder;
        //   136: invokevirtual   com/hypixel/hytale/codec/builder/BuilderField$FieldBuilder.add:()Lcom/hypixel/hytale/codec/builder/BuilderCodec$BuilderBase;
        //   139: checkcast       Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //   142: new             Lcom/hypixel/hytale/codec/KeyedCodec;
        //   145: dup            
        //   146: ldc             "Metadata"
        //   148: getstatic       com/hypixel/hytale/codec/Codec.BSON_DOCUMENT:Lcom/hypixel/hytale/codec/codecs/BsonDocumentCodec;
        //   151: invokespecial   com/hypixel/hytale/codec/KeyedCodec.<init>:(Ljava/lang/String;Lcom/hypixel/hytale/codec/Codec;)V
        //   154: invokedynamic   BootstrapMethod #11, accept:()Ljava/util/function/BiConsumer;
        //   159: invokedynamic   BootstrapMethod #12, apply:()Ljava/util/function/Function;
        //   164: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.addField:(Lcom/hypixel/hytale/codec/KeyedCodec;Ljava/util/function/BiConsumer;Ljava/util/function/Function;)Lcom/hypixel/hytale/codec/builder/BuilderCodec$BuilderBase;
        //   167: checkcast       Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //   170: invokedynamic   BootstrapMethod #13, accept:()Ljava/util/function/BiConsumer;
        //   175: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.afterDecode:(Ljava/util/function/BiConsumer;)Lcom/hypixel/hytale/codec/builder/BuilderCodec$BuilderBase;
        //   178: checkcast       Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //   181: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.build:()Lcom/hypixel/hytale/codec/builder/BuilderCodec;
        //   184: putstatic       com/hypixel/hytale/server/core/inventory/MaterialQuantity.CODEC:Lcom/hypixel/hytale/codec/builder/BuilderCodec;
        //   187: return         
        // 
        // The error that occurred was:
        // 
        // java.lang.UnsupportedOperationException: The requested operation is not supported.
        //     at com.strobel.util.ContractUtils.unsupported(ContractUtils.java:27)
        //     at com.strobel.assembler.metadata.TypeReference.getRawType(TypeReference.java:284)
        //     at com.strobel.assembler.metadata.TypeReference.getRawType(TypeReference.java:279)
        //     at com.strobel.assembler.metadata.TypeReference.makeGenericType(TypeReference.java:154)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitParameterizedType(TypeSubstitutionVisitor.java:225)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitParameterizedType(TypeSubstitutionVisitor.java:25)
        //     at com.strobel.assembler.metadata.ParameterizedType.accept(ParameterizedType.java:103)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visit(TypeSubstitutionVisitor.java:40)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitMethod(TypeSubstitutionVisitor.java:314)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferCall(TypeAnalysis.java:2611)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1040)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:782)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:778)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1510)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:790)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferCall(TypeAnalysis.java:2689)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1040)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:782)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:778)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1510)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:790)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferCall(TypeAnalysis.java:2689)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1040)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:782)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:778)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1083)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:684)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypesForVariables(TypeAnalysis.java:593)
        //     at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:405)
        //     at com.strobel.decompiler.ast.TypeAnalysis.run(TypeAnalysis.java:95)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:109)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:42)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:206)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:93)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:868)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:761)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:638)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:605)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:195)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:162)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:137)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.buildAst(JavaLanguage.java:71)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.decompileType(JavaLanguage.java:59)
        //     at com.strobel.decompiler.DecompilerDriver.decompileType(DecompilerDriver.java:333)
        //     at com.strobel.decompiler.DecompilerDriver.decompileJar(DecompilerDriver.java:254)
        //     at com.strobel.decompiler.DecompilerDriver.main(DecompilerDriver.java:129)
        // 
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }
}
