/* © SRSoftware 2025 */
package de.srsoftware.umbrella.documents;

import de.srsoftware.document.api.Document;
import de.srsoftware.document.api.DocumentFactory;
import de.srsoftware.document.api.DocumentRegistry;
import java.util.stream.Stream;

public class TemplateProcessor implements DocumentFactory {

	private DocumentRegistry registry;

	private Document createGenerator(final Document source) {
		return new TemplateDoc() {
			protected Document source() {
				return source;
			}
		};
	}

	@Override
	public String description() {
		return "Creates documents from template files";
	}

	@Override
	public Stream<Document> documents() {
		return this.registry.documents().filter(document -> document.name().endsWith(".template")).map(this::createGenerator);
	}

	@Override
	public DocumentFactory setRegistry(DocumentRegistry registry) {
		this.registry = registry;
		return this;
	}
}
