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

package com.hypixel.hytale.server.npc.asset.builder.validators;

import java.lang.invoke.CallSite;
import java.lang.reflect.UndeclaredThrowableException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.StringConcatFactory;
import java.lang.invoke.MethodType;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import javax.annotation.Nonnull;

public class IntSequenceValidator extends IntArrayValidator
{
    private static final IntSequenceValidator VALIDATOR_BETWEEN_01;
    private static final IntSequenceValidator VALIDATOR_BETWEEN_01_WEAKLY_MONOTONIC;
    private static final IntSequenceValidator VALIDATOR_BETWEEN_01_MONOTONIC;
    private final RelationalOperator relationLower;
    private final int lower;
    private final RelationalOperator relationUpper;
    private final int upper;
    private final RelationalOperator relationSequence;
    
    private IntSequenceValidator(final RelationalOperator relationLower, final int lower, final RelationalOperator relationUpper, final int upper, final RelationalOperator relationSequence) {
        this.lower = lower;
        this.upper = upper;
        this.relationLower = relationLower;
        this.relationUpper = relationUpper;
        this.relationSequence = relationSequence;
    }
    
    public static IntSequenceValidator between01() {
        return IntSequenceValidator.VALIDATOR_BETWEEN_01;
    }
    
    public static IntSequenceValidator between01WeaklyMonotonic() {
        return IntSequenceValidator.VALIDATOR_BETWEEN_01_WEAKLY_MONOTONIC;
    }
    
    public static IntSequenceValidator between01Monotonic() {
        return IntSequenceValidator.VALIDATOR_BETWEEN_01_MONOTONIC;
    }
    
    @Nonnull
    public static IntSequenceValidator between(final int lower, final int upper) {
        return new IntSequenceValidator(RelationalOperator.GreaterEqual, lower, RelationalOperator.LessEqual, upper, null);
    }
    
    @Nonnull
    public static IntSequenceValidator betweenWeaklyMonotonic(final int lower, final int upper) {
        return new IntSequenceValidator(RelationalOperator.GreaterEqual, lower, RelationalOperator.LessEqual, upper, RelationalOperator.LessEqual);
    }
    
    @Nonnull
    public static IntSequenceValidator betweenMonotonic(final int lower, final int upper) {
        return new IntSequenceValidator(RelationalOperator.GreaterEqual, lower, RelationalOperator.LessEqual, upper, RelationalOperator.Less);
    }
    
    @Nonnull
    public static IntSequenceValidator fromExclToIncl(final int lower, final int upper) {
        return new IntSequenceValidator(RelationalOperator.Greater, lower, RelationalOperator.LessEqual, upper, null);
    }
    
    @Nonnull
    public static IntSequenceValidator fromExclToInclWeaklyMonotonic(final int lower, final int upper) {
        return new IntSequenceValidator(RelationalOperator.Greater, lower, RelationalOperator.LessEqual, upper, RelationalOperator.LessEqual);
    }
    
    @Nonnull
    public static IntSequenceValidator fromExclToInclMonotonic(final int lower, final int upper) {
        return new IntSequenceValidator(RelationalOperator.Greater, lower, RelationalOperator.LessEqual, upper, RelationalOperator.Less);
    }
    
    @Override
    public boolean test(@Nonnull final int[] values) {
        for (int i = 0; i < values.length; ++i) {
            final int value = values[i];
            if (!IntValidator.compare(value, this.relationLower, this.lower) && IntValidator.compare(value, this.relationUpper, this.upper)) {
                return false;
            }
            if (i > 0 && this.relationSequence != null && !IntValidator.compare(values[i - 1], this.relationSequence, value)) {
                return false;
            }
        }
        return true;
    }
    
    @Nonnull
    @Override
    public String errorMessage(final int[] value) {
        return this.errorMessage0(value, "Array");
    }
    
    @Nonnull
    @Override
    public String errorMessage(final int[] value, final String name) {
        return this.errorMessage0(value, "\"" + name);
    }
    
    @Nonnull
    private String errorMessage0(final int[] value, final String name) {
        return name + ((this.relationLower == null) ? "" : (" values should be " + this.relationLower.asText() + " " + this.lower + " and ")) + ((this.relationUpper == null) ? "" : /* invokedynamic(!) */ProcyonInvokeDynamicHelper_18.invoke(this.relationUpper.asText(), this.upper)) + ((this.relationSequence == null) ? "" : /* invokedynamic(!) */ProcyonInvokeDynamicHelper_19.invoke(this.relationSequence.asText())) + " but is " + Arrays.toString(value);
    }
    
    static {
        VALIDATOR_BETWEEN_01 = new IntSequenceValidator(RelationalOperator.GreaterEqual, 0, RelationalOperator.LessEqual, 1, null);
        VALIDATOR_BETWEEN_01_WEAKLY_MONOTONIC = new IntSequenceValidator(RelationalOperator.GreaterEqual, 0, RelationalOperator.LessEqual, 1, RelationalOperator.LessEqual);
        VALIDATOR_BETWEEN_01_MONOTONIC = new IntSequenceValidator(RelationalOperator.GreaterEqual, 0, RelationalOperator.LessEqual, 1, RelationalOperator.Less);
    }
    
    // This helper class was generated by Procyon to approximate the behavior of an
    // 'invokedynamic' instruction that it doesn't know how to interpret.
    private static final class ProcyonInvokeDynamicHelper_18
    {
        private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
        private static MethodHandle handle;
        private static volatile int fence;
        
        private static MethodHandle handle() {
            final MethodHandle handle = ProcyonInvokeDynamicHelper_18.handle;
            if (handle != null)
                return handle;
            return ProcyonInvokeDynamicHelper_18.ensureHandle();
        }
        
        private static MethodHandle ensureHandle() {
            ProcyonInvokeDynamicHelper_18.fence = 0;
            MethodHandle handle = ProcyonInvokeDynamicHelper_18.handle;
            if (handle == null) {
                MethodHandles.Lookup lookup = ProcyonInvokeDynamicHelper_18.LOOKUP;
                try {
                    handle = ((CallSite)StringConcatFactory.makeConcatWithConstants(lookup, "makeConcatWithConstants", MethodType.methodType(String.class, String.class, int.class), " values should be \u0001 \u0001 and ")).dynamicInvoker();
                }
                catch (Throwable t) {
                    throw new UndeclaredThrowableException(t);
                }
                ProcyonInvokeDynamicHelper_18.fence = 1;
                ProcyonInvokeDynamicHelper_18.handle = handle;
                ProcyonInvokeDynamicHelper_18.fence = 0;
            }
            return handle;
        }
        
        private static String invoke(String p0, int p1) {
            try {
                return ProcyonInvokeDynamicHelper_18.handle().invokeExact(p0, p1);
            }
            catch (Throwable t) {
                throw new UndeclaredThrowableException(t);
            }
        }
    }
    
    // This helper class was generated by Procyon to approximate the behavior of an
    // 'invokedynamic' instruction that it doesn't know how to interpret.
    private static final class ProcyonInvokeDynamicHelper_19
    {
        private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
        private static MethodHandle handle;
        private static volatile int fence;
        
        private static MethodHandle handle() {
            final MethodHandle handle = ProcyonInvokeDynamicHelper_19.handle;
            if (handle != null)
                return handle;
            return ProcyonInvokeDynamicHelper_19.ensureHandle();
        }
        
        private static MethodHandle ensureHandle() {
            ProcyonInvokeDynamicHelper_19.fence = 0;
            MethodHandle handle = ProcyonInvokeDynamicHelper_19.handle;
            if (handle == null) {
                MethodHandles.Lookup lookup = ProcyonInvokeDynamicHelper_19.LOOKUP;
                try {
                    handle = ((CallSite)StringConcatFactory.makeConcatWithConstants(lookup, "makeConcatWithConstants", MethodType.methodType(String.class, String.class), " succeeding values should be \u0001 preceding values ")).dynamicInvoker();
                }
                catch (Throwable t) {
                    throw new UndeclaredThrowableException(t);
                }
                ProcyonInvokeDynamicHelper_19.fence = 1;
                ProcyonInvokeDynamicHelper_19.handle = handle;
                ProcyonInvokeDynamicHelper_19.fence = 0;
            }
            return handle;
        }
        
        private static String invoke(String p0) {
            try {
                return ProcyonInvokeDynamicHelper_19.handle().invokeExact(p0);
            }
            catch (Throwable t) {
                throw new UndeclaredThrowableException(t);
            }
        }
    }
}
