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

import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

import org.junit.jupiter.api.Test;

class SectionIdentifierTest {

    @Test
    void testSectionIdentifier() {

        SectionIdentifier identifier = SectionIdentifier.fromSearchText("1.1.2: Headline");
        assertEquals(SectionIdentifier.Format.NUMERICAL, identifier.getFormat());
        assertEquals(3, identifier.level());
        assertEquals(List.of(1, 1, 2), identifier.getIdentifiers());

        SectionIdentifier child = SectionIdentifier.asChildOf(identifier);
        assertTrue(child.isChildOf(identifier));

        SectionIdentifier parent = SectionIdentifier.fromSearchText("1.1: Headline");
        assertTrue(parent.isParentOf(identifier));
    }


    @Test
    void testSectionIdentifier2() {

        SectionIdentifier identifier = SectionIdentifier.fromSearchText("A.1.2: Headline");
        assertEquals(SectionIdentifier.Format.ALPHANUMERIC, identifier.getFormat());
        assertEquals(3, identifier.level());
        assertEquals(List.of(1, 1, 2), identifier.getIdentifiers());
    }


    @Test
    void testSectionIdentifier3() {

        SectionIdentifier identifier = SectionIdentifier.fromSearchText("D.1.2: Headline");
        assertEquals(SectionIdentifier.Format.ALPHANUMERIC, identifier.getFormat());
        assertEquals(3, identifier.level());
        assertEquals(List.of(4, 1, 2), identifier.getIdentifiers());
    }


    @Test
    void testSectionIdentifier4() {

        SectionIdentifier identifier = SectionIdentifier.fromSearchText("4.1.2.4: Headline");
        assertEquals(SectionIdentifier.Format.NUMERICAL, identifier.getFormat());
        assertEquals(4, identifier.level());
        assertEquals(List.of(4, 1, 2, 4), identifier.getIdentifiers());
    }


    @Test
    void testSectionIdentifier5() {

        SectionIdentifier identifier = SectionIdentifier.fromSearchText("D.1.2.4.5: Headline");
        assertEquals(SectionIdentifier.Format.ALPHANUMERIC, identifier.getFormat());
        assertEquals(4, identifier.level());
        assertEquals(List.of(4, 1, 2, 4), identifier.getIdentifiers());
    }


    @Test
    void testSectionIdentifier6() {

        SectionIdentifier identifier = SectionIdentifier.fromSearchText("d.1.2.4.5: Headline");
        assertEquals(SectionIdentifier.Format.ALPHANUMERIC, identifier.getFormat());
        assertEquals(4, identifier.level());
        assertEquals(List.of(4, 1, 2, 4), identifier.getIdentifiers());
    }


    @Test
    void testSectionIdentifier7() {

        SectionIdentifier identifier = SectionIdentifier.fromSearchText("4.1.2.4.5: Headline");
        assertEquals(SectionIdentifier.Format.NUMERICAL, identifier.getFormat());
        assertEquals(4, identifier.level());
        assertEquals(List.of(4, 1, 2, 4), identifier.getIdentifiers());
    }

    @Test
    void testFalsePositive111() {
        SectionIdentifier identifier = SectionIdentifier.fromSearchText("111: Headline");
        assertEquals(SectionIdentifier.Format.NUMERICAL, identifier.getFormat());
        assertEquals(1, identifier.level());
    }

}