package com.knecon.fforesight.service.layoutparser.processor.model.text;

import java.util.ArrayList;
import java.util.List;
import com.knecon.fforesight.service.layoutparser.processor.utils.TextNormalizationUtilities;

import lombok.Getter;

@Getter
public class SearchableText {

    private final List<TextPositionSequence> sequences = new ArrayList<>();


    public void add(TextPositionSequence textPositionSequence) {

        sequences.add(textPositionSequence);
    }


    public void addAll(List<TextPositionSequence> textPositionSequences) {

        sequences.addAll(textPositionSequences);
    }


    @Override
    public String toString() {

        return buildString(sequences);
    }


    public static String buildString(List<TextPositionSequence> sequences) {

        StringBuilder sb = new StringBuilder();
        for (TextPositionSequence word : sequences) {
            sb.append(word);
            sb.append(' ');
        }
        String text = sb.toString();
        text = TextNormalizationUtilities.removeHyphenLineBreaks(text);
        text = TextNormalizationUtilities.removeLineBreaks(text);
        text = TextNormalizationUtilities.removeRepeatingWhitespaces(text);
        return text;
    }

}
