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

package com.hypixel.hytale.server.npc.util.expression.compile;

import javax.annotation.Nullable;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.util.expression.ExecutionContext;
import com.hypixel.hytale.server.npc.util.expression.Scope;
import java.util.function.Function;
import com.hypixel.hytale.server.npc.util.expression.ValueType;

public class OperatorUnary
{
    private Token token;
    private ValueType argument;
    private ValueType result;
    private Function<Scope, ExecutionContext.Instruction> codeGen;
    @Nonnull
    private static OperatorUnary[] operators;
    
    private OperatorUnary(final Token token, final ValueType argument, final ValueType result, final Function<Scope, ExecutionContext.Instruction> codeGen) {
        this.token = token;
        this.argument = argument;
        this.result = result;
        this.codeGen = codeGen;
    }
    
    public boolean hasCodeGen() {
        return this.codeGen != null;
    }
    
    public ValueType getResultType() {
        return this.result;
    }
    
    public Function<Scope, ExecutionContext.Instruction> getCodeGen() {
        return this.codeGen;
    }
    
    @Nonnull
    private static OperatorUnary of(final Token token, final ValueType argument, final ValueType result, final Function<Scope, ExecutionContext.Instruction> codeGen) {
        return new OperatorUnary(token, argument, result, codeGen);
    }
    
    @Nullable
    public static OperatorUnary findOperator(final Token token, final ValueType type) {
        for (final OperatorUnary op : OperatorUnary.operators) {
            if (op.token == token && op.argument == type) {
                return op;
            }
        }
        return null;
    }
    
    static {
        OperatorUnary.operators = new OperatorUnary[] { of(Token.UNARY_PLUS, ValueType.NUMBER, ValueType.NUMBER, null), of(Token.UNARY_MINUS, ValueType.NUMBER, ValueType.NUMBER, scope -> ExecutionContext.UNARY_MINUS), of(Token.LOGICAL_NOT, ValueType.BOOLEAN, ValueType.BOOLEAN, scope -> ExecutionContext.LOGICAL_NOT), of(Token.BITWISE_NOT, ValueType.NUMBER, ValueType.NUMBER, scope -> ExecutionContext.BITWISE_NOT) };
    }
}
