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

import lombok.experimental.UtilityClass;

import java.io.IOException;

/**
 * Static methods for quick usage of ResolveFormat without explicit compilation.
 *
 * All static methods compile expression, using default {@link ResolveLocale} and {@link ResolveDialect}.
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
@UtilityClass
public final class ResolveFormatUtils {

    /**
     * Executes {@link ResolveFormat#format(Object)}
     *
     * Uses default {@link ResolveLocale} and {@link ResolveDialect}
     *
     * @param pattern pattern
     * @param context context
     * @return String
     */
    public static String format(String pattern, Object context) {
        return ResolveFormat.compile(pattern).format(context);
    }

    /**
     * Executes {@link ResolveFormat#vformat(Object...)}
     *
     * Uses default {@link ResolveLocale} and {@link ResolveDialect}
     *
     * @param pattern pattern
     * @param arguments arguments
     * @return String
     */
    public static String vformat(String pattern, Object... arguments) {
        return ResolveFormat.compile(pattern).vformat(arguments);
    }

    /**
     * Executes {@link ResolveFormat#nformat(String...)}
     *
     * Uses default {@link ResolveLocale} and {@link ResolveDialect}
     *
     * @param pattern pattern
     * @param arguments arguments
     * @return String
     */
    public static String nformat(String pattern, String... arguments) {
        return ResolveFormat.compile(pattern).nformat(arguments);
    }

    /**
     * Executes {@link ResolveFormat#format(Appendable, Object)}
     *
     * Uses default {@link ResolveLocale} and {@link ResolveDialect}
     *
     * @param output output
     * @param pattern pattern
     * @param context context
     * @param <T> T
     * @return output
     * @throws IOException on buffer error
     */
    public static <T extends Appendable> T format(T output, String pattern, Object context) throws IOException {
        return ResolveFormat.compile(pattern).format(output, context);
    }

    /**
     * Executes {@link ResolveFormat#vformat(Appendable, Object...)}
     *
     * Uses default {@link ResolveLocale} and {@link ResolveDialect}
     *
     * @param output output
     * @param pattern pattern
     * @param arguments arguments
     * @param <T> T
     * @return output
     * @throws IOException on buffer error
     */
    public static <T extends Appendable> T vformat(T output, String pattern, Object... arguments) throws IOException {
        return ResolveFormat.compile(pattern).vformat(output, arguments);
    }

    /**
     * Executes {@link ResolveFormat#nformat(Appendable, String...)}
     *
     * Uses default {@link ResolveLocale} and {@link ResolveDialect}
     *
     * @param output output
     * @param pattern pattern
     * @param arguments arguments
     * @param <T> T
     * @return output
     * @throws IOException on buffer error
     */
    public static <T extends Appendable> T nformat(T output, String pattern, String... arguments) throws IOException {
        return ResolveFormat.compile(pattern).nformat(output, arguments);
    }

    /**
     *
     * Uses default {@link ResolveLocale} and {@link ResolveDialect}.
     *
     * @param pattern pattern
     * @param input input
     * @param context context
     */
    public static void parse(String pattern, String input, Object context) {
        ResolveFormat.compile(pattern).parse(input, context);
    }

}
