package com.yaoyicloud.render.test;

import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

import org.junit.Test;

import com.yaoyicloud.message.FxyProtos.Attachment;
import com.yaoyicloud.message.FxyProtos.AttachmentSection;
import com.yaoyicloud.render.AttachmentSectionRender;

public class TestAttachmentSectionRender {

    @Test
    public void testRenderDocx() throws IOException {

        byte[] content = Files
            .readAllBytes(Paths.get(getClass().getClassLoader().getResource("docx/attachments.docx").getFile()));
        AttachmentSectionRender render = new AttachmentSectionRender("../temp/");
        String retPath = render.renderDocx(
            AttachmentSection.newBuilder()
                .setSelfDeclLink("https://abc.com/111")
                .addBusinessLicenseImages(Attachment.newBuilder().setFileName("").setFileUri("https://bcd.com"))
                .addBusinessLicenseImages(Attachment.newBuilder().setFileName("yyc_past_logo.70f2a91c.png")
                    .setFileUri("https://pre.yaoeasier.com/assets/yyc_past_logo.70f2a91c.png"))
                .addBusinessLicenseImages(Attachment.newBuilder().setFileName(".pdf")
                    .setFileUri(
                        "https://yyc3-1321096020.cos.ap-beijing.myqcloud.com/declaration/20250522/1dfcf990ed6442abbf816d302298667b.pdf"
                            + "?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20250523T052431Z&X-Amz-SignedHeaders=host&X-Amz-Expires=86400"
                            + "&X-Amz-Credential=AKIDRilauFg4fDfE9B6tJoNxTvHSdovqXBfw%2F20250523%2Fap-beijing%2Fs3%2Faws4_request&X-Amz-Signature"
                            + "=45ca610048b38dd4fa54bdd7b0b926b5e40864fda1b27556da51a8665526a848"))
                .build(),
            Map.of(),
            content);

        assertTrue(retPath.length() > 0);
    }

}
