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

import java.awt.geom.Rectangle2D;

import com.knecon.fforesight.service.layoutparser.processor.model.GapInformation;
import com.knecon.fforesight.service.layoutparser.processor.model.LineInformation;
import com.knecon.fforesight.service.layoutparser.processor.model.PageContents;
import com.knecon.fforesight.service.layoutparser.processor.model.PageInformation;

import lombok.experimental.UtilityClass;

@UtilityClass
public class PageInformationService {

    public PageInformation build(PageContents pageContents) {

        LineInformation lineInformation = LineDetectionService.calculateLineInformation(pageContents.getSortedTextPositionSequences());
        Rectangle2D mainBodyTextFrame = MainBodyTextFrameExtractionService.calculateMainBodyTextFrame(lineInformation);
        GapInformation gapInformation = GapDetectionService.findGapsInLines(pageContents.getSortedTextPositionSequences(), mainBodyTextFrame);

        return new PageInformation(pageContents, lineInformation, mainBodyTextFrame, gapInformation);
    }

}
