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

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import com.knecon.fforesight.service.layoutparser.processor.model.SectionIdentifier;

class SectionIdentifierTest {

    @Test
    public void testParentOf() {

        var headline = SectionIdentifier.fromSearchText("1 Did you ever hear the tragedy of Darth Plagueis The Wise?");
        var headline1 = SectionIdentifier.fromSearchText("1.0 I thought not. It’s not a story the Jedi would tell you.");
        var headline2 = SectionIdentifier.fromSearchText("1.1  It’s a Sith legend. Darth Plagueis was a Dark Lord of the Sith, ");
        var headline3 = SectionIdentifier.fromSearchText("1.2.3 so powerful and so wise he could use the Force to influence the midichlorians to create life…");
        var headline4 = SectionIdentifier.fromSearchText("1.2.3.4 He had such a knowledge of the dark side that he could even keep the ones he cared about from dying.");
        var headline5 = SectionIdentifier.fromSearchText("1.2.3.4.5 The dark side of the Force is a pathway to many abilities some consider to be unnatural.");
        var headline6 = SectionIdentifier.fromSearchText("2.0 He became so powerful…");
        var headline7 = SectionIdentifier.fromSearchText("10000.0 the only thing he was afraid of was losing his power,");
        var headline8 = SectionIdentifier.fromSearchText("A.0 which eventually, of course, he did.");
        var headline9 = SectionIdentifier.fromSearchText("Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep.");
        var headline10 = SectionIdentifier.fromSearchText("2.1.2 Ironic.");
        var headline11 = SectionIdentifier.fromSearchText("2.He could save others from death,");
        var headline12 = SectionIdentifier.fromSearchText(" 2. but not himself.");

        var paragraph1 = SectionIdentifier.asChildOf(headline);
        assertTrue(paragraph1.isChildOf(headline));
        assertTrue(headline.isParentOf(paragraph1));
        assertFalse(paragraph1.isParentOf(headline));

        assertFalse(headline.isParentOf(headline1));
        assertTrue(headline.isParentOf(headline2));
        assertTrue(headline.isParentOf(headline3));
        assertTrue(headline.isParentOf(headline4));
        assertTrue(headline.isParentOf(headline5));
        assertTrue(headline1.isParentOf(headline2));
        assertFalse(headline1.isParentOf(headline1));
        assertTrue(headline3.isParentOf(headline4));
        assertFalse(headline4.isParentOf(headline5));
        assertFalse(headline2.isParentOf(headline3));
        assertFalse(headline2.isParentOf(headline4));
        assertTrue(headline1.isParentOf(headline3));
        assertTrue(headline1.isParentOf(headline4));
        assertFalse(headline1.isParentOf(headline6));
        assertFalse(headline1.isParentOf(headline7));
        assertFalse(headline8.isParentOf(headline1));
        assertFalse(headline8.isParentOf(headline2));
        assertFalse(headline8.isParentOf(headline3));
        assertFalse(headline8.isParentOf(headline4));
        assertFalse(headline9.isParentOf(headline9));
        assertTrue(headline10.isChildOf(headline11));
        assertTrue(headline10.isChildOf(headline12));
    }

}