package com.capgemini.framework.common;

import lombok.Getter;

/**
 * Customizable messages (using tags).
 */
@Getter
public class DynamicErrorTemplateHelper {

    private String refError;
    private final String[] tags;

    /**
     * Constructor.
     * 
     * @param refError a reference error message (with tags)
     * @param tags a list of known tags
     */
    public DynamicErrorTemplateHelper(final String refError, final String... tags) {
        this.refError = refError;
        this.tags = tags;
    }

    /**
     * Resolve a dynamic error.<br/>
     * Put each tags in theirs places.
     * 
     * @return refErrorString
     */
    public String resolve() {
        for (String tag : tags) {
            refError = refError.replaceFirst("\\{\\}", tag);
        }
        return refError;
    }
}
