package com.wmyun.farmwork.word.core.utils;

import com.deepoove.poi.template.IterableTemplate;
import com.deepoove.poi.xwpf.*;
import org.apache.poi.xwpf.usermodel.*;

/**
 * @Description: TODO
 * @Date: 2025/3/7 15:28
 * @Created: by ZZSLL
 */

public class BodyContainerFactory {

    public static BodyContainer getBodyContainer(IBody body) {
        if (body instanceof XWPFTableCell) {
            return new CellBodyContainer((XWPFTableCell) body);
        } else if (body instanceof XWPFHeaderFooter) {
            return new HeaderFooterBodyContainer((XWPFHeaderFooter) body);
        } else if (body instanceof XWPFTextboxContent) {
            return new TextBoxBodyContainer((XWPFTextboxContent) body);
        } else if (body instanceof XWPFComment) {
            return new CommentBodyContainer((XWPFComment) body);
        } else if (body instanceof XWPFStructuredDocumentTagContent) {
            return new SDTBodyContainer((XWPFStructuredDocumentTagContent) body);
        } else {
            return new DocumentBodyContainer((NiceXWPFDocument) body);
        }
    }

    public static BodyContainer getBodyContainer(XWPFRun run) {
        assert run.getParent() instanceof IBodyElement;
        return getBodyContainer(((IBodyElement) run.getParent()).getBody());
    }

    public static BodyContainer getBodyContainer(IterableTemplate iterableTemplate) {
        return getBodyContainer(iterableTemplate.getStartRun());
    }

}