package com.ycwl.basic.puzzle.fill.condition;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
 * 总是匹配策略测试
 */
@DisplayName("总是匹配策略测试")
class AlwaysConditionStrategyTest {

    private AlwaysConditionStrategy strategy;
    private ObjectMapper objectMapper;

    @BeforeEach
    void setUp() {
        strategy = new AlwaysConditionStrategy();
        objectMapper = new ObjectMapper();
    }

    @Test
    @DisplayName("应该返回正确的支持类型")
    void shouldReturnCorrectSupportedType() {
        assertEquals("ALWAYS", strategy.getSupportedType());
    }

    @Test
    @DisplayName("无论conditionValue和context如何都应该返回true")
    void shouldAlwaysReturnTrue() throws Exception {
        // Given
        String conditionValueJson = "{\"anyField\": \"anyValue\"}";
        JsonNode conditionValue = objectMapper.readTree(conditionValueJson);

        ConditionContext context = ConditionContext.builder()
                .deviceCount(4)
                .faceId(123L)
                .build();

        // When
        boolean result = strategy.evaluate(conditionValue, context);

        // Then
        assertTrue(result);
    }

    @Test
    @DisplayName("当conditionValue为null时也应该返回true")
    void shouldReturnTrueEvenWhenConditionValueIsNull() {
        // Given
        ConditionContext context = ConditionContext.builder().build();

        // When
        boolean result = strategy.evaluate(null, context);

        // Then
        assertTrue(result);
    }

    @Test
    @DisplayName("当context为空时也应该返回true")
    void shouldReturnTrueEvenWhenContextIsEmpty() throws Exception {
        // Given
        String conditionValueJson = "{}";
        JsonNode conditionValue = objectMapper.readTree(conditionValueJson);

        ConditionContext context = ConditionContext.builder().build();

        // When
        boolean result = strategy.evaluate(conditionValue, context);

        // Then
        assertTrue(result);
    }
}
