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

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

import javax.annotation.Nonnull;

public class IntRangeValidator extends IntValidator
{
    private final RelationalOperator relationLower;
    private final int lower;
    private final RelationalOperator relationUpper;
    private final int upper;
    
    public IntRangeValidator(final RelationalOperator relationLower, final int lower, final RelationalOperator relationUpper, final int upper) {
        this.lower = lower;
        this.upper = upper;
        this.relationLower = relationLower;
        this.relationUpper = relationUpper;
    }
    
    @Override
    public boolean test(final int value) {
        return IntValidator.compare(value, this.relationLower, this.lower) && IntValidator.compare(value, this.relationUpper, this.upper);
    }
    
    @Nonnull
    @Override
    public String errorMessage(final int value) {
        return this.errorMessage0(value, "Value");
    }
    
    @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 + " should be " + this.relationLower.asText() + " " + this.lower + " and " + this.relationUpper.asText() + " " + this.upper + " but is " + value;
    }
    
    @Nonnull
    public static IntRangeValidator fromInclToExcl(final int lower, final int upper) {
        return new IntRangeValidator(RelationalOperator.GreaterEqual, lower, RelationalOperator.Less, upper);
    }
    
    @Nonnull
    public static IntRangeValidator fromExclToIncl(final int lower, final int upper) {
        return new IntRangeValidator(RelationalOperator.Greater, lower, RelationalOperator.LessEqual, upper);
    }
    
    @Nonnull
    public static IntRangeValidator between(final int lower, final int upper) {
        return new IntRangeValidator(RelationalOperator.GreaterEqual, lower, RelationalOperator.LessEqual, upper);
    }
}
