package click.kamil.springstatemachineexporter.analysis.flow.eventid;

import org.junit.jupiter.api.Test;

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

class EventIdentityNormalizeTest {

    @Test
    void sameConstantTreatsBareAndQualifiedAsEqual() {
        assertThat(EventIdentityNormalize.sameConstant("PAY", "OrderEvent.PAY")).isTrue();
        assertThat(EventIdentityNormalize.sameConstant("OrderEvent.PAY", "com.example.OrderEvent.PAY")).isTrue();
        assertThat(EventIdentityNormalize.sameConstant("PAY", "SHIP")).isFalse();
        assertThat(EventIdentityNormalize.sameConstant("PAY", "<SYMBOLIC: OrderEvent.*>")).isFalse();
    }

    @Test
    void preferQualifiedKeepsDottedForm() {
        assertThat(EventIdentityNormalize.preferQualified("PAY", "OrderEvent.PAY", null))
                .isEqualTo("OrderEvent.PAY");
        assertThat(EventIdentityNormalize.preferQualified("OrderEvent.PAY", "PAY", null))
                .isEqualTo("OrderEvent.PAY");
        assertThat(EventIdentityNormalize.preferQualified("PAY", "PAY", "OrderEvent"))
                .isEqualTo("OrderEvent.PAY");
    }

    @Test
    void expandConsultAdoptPolicy() {
        assertThat(ExpandConsult.empty().adoptableAsPolyExpand()).isFalse();
        assertThat(ExpandConsult.unique(java.util.List.of("OrderEvent.PAY"), "OrderEvent").adoptableAsPolyExpand())
                .isFalse();
        assertThat(ExpandConsult.unique(java.util.List.of("OrderEvent.PAY"), "OrderEvent").isUniqueProof())
                .isTrue();
        ExpandConsult expand = ExpandConsult.enumExpand(
                java.util.List.of("OrderEvent.PAY", "OrderEvent.SHIP"), "OrderEvent");
        assertThat(expand.adoptableAsPolyExpand()).isTrue();
        assertThat(EventIdentityPolyPublish.adoptExpandOrEmpty(expand))
                .containsExactly("OrderEvent.PAY", "OrderEvent.SHIP");
        assertThat(EventIdentityPolyPublish.adoptExpandOrEmpty(
                ExpandConsult.unique(java.util.List.of("PAY"), null))).isEmpty();
    }
}
