package com.lingniu.ingest.api.event;

import org.junit.jupiter.api.Test;

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

class TelemetryFieldValueTest {

    @Test
    void createsTypedDoubleFieldWithStableMetadata() {
        TelemetryFieldValue field = TelemetryFieldValue.doubleValue(
                "total_mileage_km", 12345.6, "km", "gb32960.vehicle.totalMileageKm");

        assertThat(field.key()).isEqualTo("total_mileage_km");
        assertThat(field.valueType()).isEqualTo(TelemetryFieldValue.ValueType.DOUBLE);
        assertThat(field.value()).isEqualTo("12345.6");
        assertThat(field.unit()).isEqualTo("km");
        assertThat(field.quality()).isEqualTo(TelemetryFieldValue.Quality.GOOD);
        assertThat(field.sourcePath()).isEqualTo("gb32960.vehicle.totalMileageKm");
    }

    @Test
    void rejectsBlankFieldKey() {
        assertThatThrownBy(() -> TelemetryFieldValue.stringValue(" ", "STARTED", "", "gb32960.vehicle.state"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("key");
    }

    @Test
    void marksMissingValueExplicitly() {
        TelemetryFieldValue field = TelemetryFieldValue.missing(
                "hydrogen_remaining_kg", "kg", "gb32960.vendor.hydrogenRemaining");

        assertThat(field.valueType()).isEqualTo(TelemetryFieldValue.ValueType.STRING);
        assertThat(field.value()).isEmpty();
        assertThat(field.quality()).isEqualTo(TelemetryFieldValue.Quality.MISSING);
    }
}
