package net.minecraft.world.entity.ai.attributes;

import java.util.Objects;
import java.util.Random;
import net.minecraft.util.Mth;
import io.netty.util.internal.ThreadLocalRandom;
import java.util.UUID;
import java.util.function.Supplier;

public class AttributeModifier {
    private final double amount;
    private final Operation operation;
    private final Supplier<String> nameGetter;
    private final UUID id;
    private boolean serialize;
    
    public AttributeModifier(final String string, final double double2, final Operation a) {
        this(Mth.createInsecureUUID((Random)ThreadLocalRandom.current()), () -> string, double2, a);
    }
    
    public AttributeModifier(final UUID uUID, final String string, final double double3, final Operation a) {
        this(uUID, () -> string, double3, a);
    }
    
    public AttributeModifier(final UUID uUID, final Supplier<String> supplier, final double double3, final Operation a) {
        this.serialize = true;
        this.id = uUID;
        this.nameGetter = supplier;
        this.amount = double3;
        this.operation = a;
    }
    
    public UUID getId() {
        return this.id;
    }
    
    public String getName() {
        return this.nameGetter.get();
    }
    
    public Operation getOperation() {
        return this.operation;
    }
    
    public double getAmount() {
        return this.amount;
    }
    
    public boolean isSerializable() {
        return this.serialize;
    }
    
    public AttributeModifier setSerialize(final boolean boolean1) {
        this.serialize = boolean1;
        return this;
    }
    
    @Override
    public boolean equals(final Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || this.getClass() != object.getClass()) {
            return false;
        }
        final AttributeModifier als3 = (AttributeModifier)object;
        return Objects.equals(this.id, als3.id);
    }
    
    @Override
    public int hashCode() {
        return (this.id != null) ? this.id.hashCode() : 0;
    }
    
    @Override
    public String toString() {
        return "AttributeModifier{amount=" + this.amount + ", operation=" + this.operation + ", name='" + this.nameGetter.get() + '\'' + ", id=" + this.id + ", serialize=" + this.serialize + '}';
    }
    
    public enum Operation {
        ADDITION(0), 
        MULTIPLY_BASE(1), 
        MULTIPLY_TOTAL(2);
        
        private static final Operation[] OPERATIONS;
        private final int value;
        
        private Operation(final int integer3) {
            this.value = integer3;
        }
        
        public int toValue() {
            return this.value;
        }
        
        public static Operation fromValue(final int integer) {
            if (integer < 0 || integer >= Operation.OPERATIONS.length) {
                throw new IllegalArgumentException("No operation with value " + integer);
            }
            return Operation.OPERATIONS[integer];
        }
        
        static {
            OPERATIONS = new Operation[] { Operation.ADDITION, Operation.MULTIPLY_BASE, Operation.MULTIPLY_TOTAL };
        }
    }
}
