package org.ta.pddserver;

import org.apache.commons.codec.binary.Base64;
import org.junit.jupiter.api.Test;
import org.ta.pddserver.lotto.ImagePdfGenerator;
import org.ta.pddserver.model.to.PrintOrderInfoTO;

import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class PdfTest {
    @Test
    public void generatePDF() throws Exception {
        PrintOrderInfoTO formData = new PrintOrderInfoTO();
        formData.setExpressTag("운송장번호;");
        formData.setExpressUid("317758904816");
        formData.setLandingUid("123456789012");
        formData.setAddressUpperLeft("B-26-평64");
        formData.setAddressUpperRight("부평(대)");
        formData.setAddressBottomLeft("X 부평구 부평5동");
        formData.setAddressBottomRight("평64-이구용");
        formData.setRecipient("받는분: REN SUPING 010-3619-****21353");
        formData.setDetailedAddress("인천광역시 부평구 부평동 126-9 유진마젤란주상복합 오피스텔1205");
        formData.setOrderCore("PP25111223915187411540070");
//        new PdfUtil().printSaleInfo(formData, null);
        //System.out.println("file:" + returnString);
    }

    @Test
    public void test2() throws IOException {
        File file = new File("E:/lotte_T.png");
        FileInputStream imageInFile = new FileInputStream(file);
        byte[] imageData = new byte[(int) file.length()];
        imageInFile.read(imageData);
        String base64Image = Base64.encodeBase64String(imageData);
        System.out.println(base64Image);
    }

    @Test
    public void test3() throws Exception {
        try (FileOutputStream outputStream = new FileOutputStream("./PP25112111811160070553457.pdf")) {
            byte[] strToBytes = ImagePdfGenerator.generatePdfWithTextImage(
                    "317758904853",
                    "553",
                    "JIN JIANYU",
                    "01027179333",
                    "28488",
                    "충청북도 청주시 청원구 우암로 46 충청북도 청주시 청원구 우암동 362-21 202호",
                    "PP25112111811160070553457",
                    "M-K1-우07",
                    "X 청주시 청원구",
                    "청주우암(대)",
                    "우07-조영선");
            outputStream.write(strToBytes);
            System.out.println("文件写入成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test4() throws Exception {
        try (FileOutputStream outputStream = new FileOutputStream("./LS.pdf")) {
            byte[] strToBytes = ImagePdfGenerator.generateCode();
            outputStream.write(strToBytes);
            System.out.println("文件写入成功！");
            
        } catch (IOException e) {
            e.printStackTrace();
        } catch (FontFormatException e) {
            throw new RuntimeException(e);
        }
    }
}
