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 org.junit.jupiter.api.Test;

/**
 * Tests for {@link GuiFieldFinding}.
 */
class GuiFieldFindingTest {

    @Test
    void storesAllFields() {
        var finding = new GuiFieldFinding("source.folder", GuiMessageSeverity.ERROR, "Pflichtfeld fehlt");

        assertThat(finding.fieldKey()).isEqualTo("source.folder");
        assertThat(finding.severity()).isEqualTo(GuiMessageSeverity.ERROR);
        assertThat(finding.text()).isEqualTo("Pflichtfeld fehlt");
    }

    @Test
    void errorFactory_createsFindingWithErrorSeverity() {
        var finding = GuiFieldFinding.error("target.folder", "Ordner nicht vorhanden");

        assertThat(finding.severity()).isEqualTo(GuiMessageSeverity.ERROR);
        assertThat(finding.fieldKey()).isEqualTo("target.folder");
        assertThat(finding.text()).isEqualTo("Ordner nicht vorhanden");
    }

    @Test
    void warningFactory_createsFindingWithWarningSeverity() {
        var finding = GuiFieldFinding.warning("max.text.characters", "Sehr hohe Zeichenzahl konfiguriert");

        assertThat(finding.severity()).isEqualTo(GuiMessageSeverity.WARNING);
        assertThat(finding.fieldKey()).isEqualTo("max.text.characters");
    }

    @Test
    void rejectsNullFieldKey() {
        assertThatNullPointerException()
                .isThrownBy(() -> new GuiFieldFinding(null, GuiMessageSeverity.ERROR, "text"));
    }

    @Test
    void rejectsNullSeverity() {
        assertThatNullPointerException()
                .isThrownBy(() -> new GuiFieldFinding("field", null, "text"));
    }

    @Test
    void rejectsNullText() {
        assertThatNullPointerException()
                .isThrownBy(() -> new GuiFieldFinding("field", GuiMessageSeverity.ERROR, null));
    }

    @Test
    void equality_basedOnAllFields() {
        var a = GuiFieldFinding.error("source.folder", "fehlt");
        var b = GuiFieldFinding.error("source.folder", "fehlt");
        var c = GuiFieldFinding.error("target.folder", "fehlt");

        assertThat(a).isEqualTo(b);
        assertThat(a).isNotEqualTo(c);
    }
}
