package com.knecon.fforesight.service.layoutparser.processor.model.graph.nodes;

import com.knecon.fforesight.service.layoutparser.internal.api.data.redaction.NodeType;
import com.knecon.fforesight.service.layoutparser.processor.model.graph.NodeVisitor;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = true)
public class Section extends AbstractSemanticNode {

    @Override
    public NodeType getType() {

        return NodeType.SECTION;
    }


    public Headline getHeadline() {

        return streamChildrenOfType(NodeType.HEADLINE).map(node -> (Headline) node)
                .findFirst().orElseGet(() -> getParent().getHeadline());
    }


    @Override
    public void accept(NodeVisitor visitor) {

        visitor.visit(this);
    }


    public boolean hasTables() {

        return streamAllSubNodesOfType(NodeType.TABLE).findAny().isPresent();
    }


    @Override
    public String toString() {

        return getTreeId() + ": " + NodeType.SECTION + ": " + this.getTextBlock().buildSummary();
    }

}
