package com.ai.trackwalker.uavaccess.flighthub;

import org.junit.jupiter.api.Test;

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

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

class DeviceTopologyServiceTest {
    @Test
    void flattensDroneAndDockTopologyIntoStableVendorDevices() {
        DeviceTopologyService service = new DeviceTopologyService(null, null, null);
        Map<String, Object> drone = Map.of(
                "device_sn", "DRONE-01",
                "device_model", Map.of("key", "0-91-0", "name", "Matrice 3D", "class", "drone"),
                "device_online_status", true,
                "parent_sns", List.of("DOCK-01"),
                "device_state", Map.of(
                        "longitude", 113.94,
                        "latitude", 22.56,
                        "battery_capacity_percent", 78,
                        "firmware_version", "08.01"
                )
        );
        Map<String, Object> dock = Map.of(
                "device_sn", "DOCK-01",
                "device_model", Map.of("key", "3-3-0", "name", "DJI Dock 3", "class", "airport"),
                "device_online_status", true,
                "parent_sns", List.of(),
                "device_state", Map.of("longitude", 113.94, "latitude", 22.56, "rainfall", "none")
        );

        List<Map<String, Object>> result = service.flatten(Map.of(
                "list", List.of(Map.of("host", drone, "parents", List.of(dock), "nodes", List.of()))
        ));

        assertThat(result).hasSize(2);
        assertThat(result.get(0))
                .containsEntry("vendor_device_id", "DRONE-01")
                .containsEntry("parent_vendor_device_id", "DOCK-01")
                .containsEntry("device_type", "AIRCRAFT")
                .containsEntry("status", "ONLINE");
        assertThat(result.get(1))
                .containsEntry("vendor_device_id", "DOCK-01")
                .containsEntry("device_type", "DOCK");
    }
}
