package click.kamil.springstatemachineexporter.analysis.resolver;

import click.kamil.springstatemachineexporter.analysis.model.TriggerPoint;
import click.kamil.springstatemachineexporter.analysis.resolver.StateMachineTypeResolver.MachineTypes;
import org.junit.jupiter.api.Test;

import java.util.List;

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

class MachineEnumCanonicalizerBoundValueOfTest {

    @Test
    void shouldExpandSingleBoundEventLiteralForValueOfTrigger() {
        TriggerPoint trigger = TriggerPoint.builder()
                .event("OrderEvent.valueOf(eventString.toUpperCase())")
                .constraint("\"ORDER\".equalsIgnoreCase(machineType) && \"PAY\".equalsIgnoreCase(event)")
                .external(true)
                .build();
        StateMachineTypeResolver.MachineTypes machineTypes =
                new StateMachineTypeResolver.MachineTypes(
                        "com.example.order.OrderState",
                        "com.example.order.OrderEvent");

        TriggerPoint expanded = MachineEnumCanonicalizer.expandBoundValueOfFromConstraints(
                trigger, machineTypes, null);

        assertThat(expanded.getPolymorphicEvents())
                .containsExactly("com.example.order.OrderEvent.PAY");
        assertThat(expanded.isExternal()).isFalse();
        assertThat(expanded.isAmbiguous()).isFalse();
    }
}
