package org.raddatz.familienarchiv.document;

import org.junit.jupiter.api.Test;
import org.raddatz.familienarchiv.document.MatchOffset;
import org.raddatz.familienarchiv.document.SearchMatchData;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class SearchMatchDataTest {

    @Test
    void transcription_snippet_is_nullable() {
        SearchMatchData data = new SearchMatchData(null, List.of(), false, List.of(), List.of(), List.of(), null, List.of());

        assertThat(data.transcriptionSnippet()).isNull();
    }

    @Test
    void non_null_list_fields_are_empty_by_default_in_empty_factory() {
        SearchMatchData data = SearchMatchData.empty();

        assertThat(data.transcriptionSnippet()).isNull();
        assertThat(data.titleOffsets()).isEmpty();
        assertThat(data.matchedReceiverIds()).isEmpty();
        assertThat(data.matchedTagIds()).isEmpty();
        assertThat(data.senderMatched()).isFalse();
    }

    @Test
    void holds_all_field_values() {
        MatchOffset offset = new MatchOffset(0, 4);
        SearchMatchData data = new SearchMatchData(
                "schreibt dir aus dem Feld",
                List.of(offset),
                true,
                List.of(),
                List.of(),
                List.of(),
                null,
                List.of()
        );

        assertThat(data.transcriptionSnippet()).isEqualTo("schreibt dir aus dem Feld");
        assertThat(data.titleOffsets()).containsExactly(offset);
        assertThat(data.senderMatched()).isTrue();
    }

    @Test
    void snippet_offsets_are_empty_in_empty_factory() {
        SearchMatchData data = SearchMatchData.empty();
        assertThat(data.snippetOffsets()).isEmpty();
    }

    @Test
    void snippet_offsets_carry_through_constructor() {
        MatchOffset offset = new MatchOffset(5, 3);
        SearchMatchData data = new SearchMatchData(
                "Das ist ein furchtbares Bild",
                List.of(),
                false,
                List.of(),
                List.of(),
                List.of(offset),
                null,
                List.of()
        );
        assertThat(data.snippetOffsets()).containsExactly(offset);
    }
}
