package com.zjrs.appcomm.template.word.builder;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ExportBuilder<E> {
	
	private ExportDefinition<E> exportDefinition;
	public ExportBuilder(Class<E> dataClass) {
		this.exportDefinition = new ExportDefinition<>(dataClass);
	}
	
	public ExportDefinition<E> build() {
		return exportDefinition;
	}

	/** docx对象 */
	public ExportBuilder<E> document(XWPFDocument document) {
		exportDefinition.setDocument(document);
		return this;
	}
	public ExportBuilder<E> document(InputStream is) throws IOException {
		XWPFDocument document = new XWPFDocument(is);
		return document(document);
	}
	public ExportBuilder<E> sheet(byte[] content) throws IOException {
		try (InputStream is = new ByteArrayInputStream(content)) {
			return document(is);
		}
	}

	/** 数据 */
	public ExportBuilder<E> data(E data) {
		exportDefinition.setData(data);
		return this;
	}
}
