package markup;

import java.util.List;

/**
 * @author Nikita Doschennikov (me@fymio.us)
 */
public abstract class AbstractList implements ContainsInListItem {

    private final List<ListItem> items;
    private final String highlight;
    private final String texBegin;
    private final String texEnd;

    protected AbstractList(
        List<ListItem> items,
        String highlight,
        String texBegin,
        String texEnd
    ) {
        this.items = items;
        this.highlight = highlight;
        this.texBegin = texBegin;
        this.texEnd = texEnd;
    }

    @Override
    public void toHtml(StringBuilder sb) {
        sb.append("<").append(highlight).append(">");
        for (ListItem item : items) {
            item.toHtml(sb);
        }
        sb.append("</").append(highlight).append(">");
    }

    @Override
    public void toMarkdown(StringBuilder sb) {}

    @Override
    public void toTex(StringBuilder sb) {
        sb.append(texBegin);
        for (ListItem item : items) {
            item.toTex(sb);
        }
        sb.append(texEnd);
    }
}
