/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.reflection.util;

import lombok.experimental.UtilityClass;

import net.ranides.assira.generic.Wrapper;
import net.ranides.assira.reflection.IClass;
import net.ranides.assira.reflection.ResolvePattern;

/**
 * Helper static methods for ResolvePattern.
 * Every static method compiles expression on the fly.
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
@UtilityClass
public final class ResolveUtils {

    /**
     * Resolves "expression" against "that" object.
     * Please look at {@link ResolvePattern#get(Object)}.
     *
     * @param that that
     * @param expression expression
     * @return Object
     */
    public static Object get(Object that, String expression) {
        return ResolvePattern.compile(expression).get(that);
    }

    /**
     * Changes state of "that" object using "expression".
     * Please look at {@link ResolvePattern#set(Object, Object)}.
     *
     * @param that that
     * @param expression expression
     * @param value value
     */
    public static void set(Object that, String expression, Object value) {
        ResolvePattern.compile(expression).set(that, value);
    }

    /**
     * Changes state of "that" object using "expression".
     * Please look at {@link ResolvePattern#replace(Object, Object)}.
     *
     * @param that that
     * @param expression expression
     * @param value value
     * @return previous value
     */
    public static Object replace(Object that, String expression, Object value) {
        return ResolvePattern.compile(expression).replace(that, value);
    }

    /**
     * Evaluates type of expression against "that" object.
     * Please look at {@link ResolvePattern#type(Object)}.
     *
     * @param that that
     * @param expression expression
     * @return type
     */
    public static IClass<?> type(Object that, String expression) {
        return ResolvePattern.compile(expression).type(that);
    }

    /**
     * Binds provided expression to "that" object.
     * Please look at {@link ResolvePattern#bind(Object)}.
     *
     * @param that that
     * @param expression expression
     * @return wrapper
     */
    public static Wrapper<Object> bind(Object that, String expression) {
        return ResolvePattern.compile(expression).bind(that);
    }
    
    
}
