package de.gecheckt.pdf.umbenenner.adapter.in.gui.editor;

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

import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

import de.gecheckt.pdf.umbenenner.application.validation.technicaltest.CorrectionPlan;
import de.gecheckt.pdf.umbenenner.application.validation.technicaltest.CorrectionSuggestion;

/**
 * Tests für {@link ConfirmationDialogContent}.
 */
class ConfirmationDialogContentTest {

    @Test
    void fromPlan_extractsDescriptionsInOrder() {
        var s1 = new CorrectionSuggestion.CreateDirectory("/path/a", "Zielordner anlegen");
        var s2 = new CorrectionSuggestion.CreatePromptFile("/path/prompt.txt", "Prompt-Datei erzeugen", 60);
        var plan = new CorrectionPlan(List.of(s1, s2));

        var content = ConfirmationDialogContent.fromPlan(plan);

        assertThat(content.correctionLines()).containsExactly(
                "Zielordner anlegen",
                "Prompt-Datei erzeugen");
        assertThat(content.title()).isNotBlank();
        assertThat(content.introText()).isNotBlank();
        assertThat(content.hasCorrections()).isTrue();
    }

    @Test
    void fromPlan_emptyPlan_hasNoCorrections() {
        var content = ConfirmationDialogContent.fromPlan(CorrectionPlan.empty());
        assertThat(content.hasCorrections()).isFalse();
        assertThat(content.correctionLines()).isEmpty();
    }

    @Test
    void fromPlan_nullPlanThrows() {
        assertThatNullPointerException()
                .isThrownBy(() -> ConfirmationDialogContent.fromPlan(null));
    }

    @Test
    void correctionLinesAreImmutable() {
        var content = new ConfirmationDialogContent("Titel", "Intro", new ArrayList<>(List.of("Zeile 1")));
        assertThat(content.correctionLines()).hasSize(1);
    }

    @Test
    void nullTitleThrows() {
        assertThatNullPointerException()
                .isThrownBy(() -> new ConfirmationDialogContent(null, "intro", List.of()));
    }

    @Test
    void nullIntroTextThrows() {
        assertThatNullPointerException()
                .isThrownBy(() -> new ConfirmationDialogContent("title", null, List.of()));
    }

    @Test
    void nullCorrectionLinesThrows() {
        assertThatNullPointerException()
                .isThrownBy(() -> new ConfirmationDialogContent("title", "intro", null));
    }

    @Test
    void equality() {
        var a = new ConfirmationDialogContent("T", "I", List.of("Z1"));
        var b = new ConfirmationDialogContent("T", "I", List.of("Z1"));
        assertThat(a).isEqualTo(b);
    }
}
