package com.knecon.fforesight.service.layoutparser.server.services;

import java.nio.file.Path;
import java.util.List;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import com.knecon.fforesight.service.layoutparser.processor.model.PageContents;
import com.knecon.fforesight.service.layoutparser.processor.model.text.TextPositionSequence;
import com.knecon.fforesight.service.layoutparser.processor.utils.RectangleTransformations;
import com.knecon.fforesight.service.layoutparser.processor.services.PageContentExtractor;
import com.knecon.fforesight.service.layoutparser.server.utils.visualizations.PdfDraw;

import lombok.SneakyThrows;

class PageContentExtractorTest {

    @Test
    @SneakyThrows
    public void testTextPositionSequenceExtraction() {

        String fileName = "files/syngenta/CustomerFiles/Documine/Flora/SOLICITA_VICTRATO-GOLD-II_Item 21_Mutacao_Genica.pdf";
        var tmpFileName = Path.of("/tmp/").resolve(Path.of(fileName).getFileName() + "_TEXT_POSITION_SEQUENCES.pdf").toString();

        List<PageContents> textPositionPerPage = PageContentExtractor.getSortedPageContents(fileName);

        PdfDraw.drawRectanglesPerPageNumberedByLine(fileName,
                textPositionPerPage.stream()
                        .map(t -> t.getSortedTextPositionSequences()
                                .stream()
                                .map(TextPositionSequence::getRectangle)
                                .map(RectangleTransformations::toRectangle2D)
                                //.map(textPositionSequence -> (Rectangle2D) new Rectangle2D.Double(textPositionSequence.getMaxXDirAdj(), textPositionSequence.getMaxYDirAdj(), textPositionSequence.getWidth(), textPositionSequence.getHeight()))
                                .map(List::of)
                                .toList())
                        .toList(), tmpFileName);
    }

}