package com.ai.trackwalker.model;

import org.junit.jupiter.api.Test;

import java.util.Map;

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

class ModelParameterValidatorTest {
    private final ModelParameterValidator validator = new ModelParameterValidator();

    @Test
    void acceptsValidDetectionParameters() {
        ModelParameterValidator.ValidationResult result = validator.validate("detection", Map.of(
                "confidence_threshold", 0.55,
                "nms_iou_threshold", 0.45,
                "max_detections", 100,
                "input_size", 960,
                "precision", "FP16",
                "enable_tiling", true,
                "tile_overlap", 0.2
        ));

        assertThat(result.valid()).isTrue();
        assertThat(result.errors()).isEmpty();
        assertThat(result.resourceEstimate()).containsKey("memory_gb");
    }

    @Test
    void rejectsPointCloudIcpDistanceBelowVoxelSize() {
        ModelParameterValidator.ValidationResult result = validator.validate("pointcloud", Map.of(
                "voxel_size_m", 0.2,
                "outlier_neighbors", 20,
                "outlier_std_ratio", 2.0,
                "icp_max_distance_m", 0.1,
                "icp_iterations", 80,
                "registration_error_limit_m", 0.1
        ));

        assertThat(result.valid()).isFalse();
        assertThat(result.errors()).anyMatch(error -> "cross_field".equals(error.code()));
    }

    @Test
    void warnsAboutLowThermalEmissivity() {
        ModelParameterValidator.ValidationResult result = validator.validate("thermal", Map.of(
                "emissivity", 0.55,
                "ambient_temperature_c", 25,
                "reflected_temperature_c", 25,
                "distance_m", 30,
                "humidity_percent", 60,
                "hotspot_threshold_c", 70,
                "relative_rise_threshold_c", 20
        ));

        assertThat(result.valid()).isTrue();
        assertThat(result.warnings()).anyMatch(warning -> "calibration_required".equals(warning.code()));
    }
}
