package cz.moneta.test.harness.support.util;

import org.stringtemplate.v4.ST;

/**
 * StringTemplate
 */
public class Template {

    ST template;

    public static Template fromFilepath(String filePath) {
        return new Template(FileReader.readFileFromResources(filePath));
    }

    public Template(String templateString) {
        this.template = new ST(templateString);
    }

    public Template set(String variable, String value) {
        this.template.add(variable, value);
        return this;
    }

    public Template set(String variable, Template value) {
        this.template.add(variable, value.render());
        return this;
    }

    public Template setQuoted(String variable, String value) {
        return set(variable, (value != null) ? String.format("\"%s\"", value) : null);
    }

    public Template setQuoted(String variable, Template value) {
        return setQuoted(variable, value.render());
    }

    public Template setRawAttribute(String variable, Object value) {
        this.template.add(variable, value);
        return this;
    }

    public String render() {
        return template.render();
    }
}

