package com.lingniu.ingest.inbound.mqtt.config;

import com.lingniu.ingest.core.dispatcher.Dispatcher;
import com.lingniu.ingest.identity.VehicleIdentity;
import com.lingniu.ingest.identity.VehicleIdentitySource;
import com.lingniu.ingest.inbound.mqtt.profile.MqttProfileRegistry;
import org.junit.jupiter.api.Test;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.StandardEnvironment;

import java.util.List;
import java.util.Map;

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

class MqttInboundAutoConfigurationTest {

    @Test
    void doesNotCreateEndpointFromLegacySingleEndpointEnvironmentKeys() {
        MqttInboundProperties props = new MqttInboundProperties();
        StandardEnvironment environment = new StandardEnvironment();
        environment.getPropertySources().addFirst(new MapPropertySource("test", Map.of(
                "MQTT_URI", "tcp://127.0.0.1:1883",
                "MQTT_TOPIC", "/legacy/#",
                "YUTONG_MQTT_ENDPOINT_NAME", "legacy-yutong")));

        new MqttInboundAutoConfiguration().mqttEndpointManager(
                props,
                new MqttProfileRegistry(List.of()),
                lookup -> new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN),
                new Dispatcher(null, null, null, null, null));

        assertThat(props.getEndpoints()).isEmpty();
        assertThat(environment.getProperty("MQTT_URI")).isEqualTo("tcp://127.0.0.1:1883");
    }
}
