use pretty_assertions::assert_eq;
use rstest::rstest;
use serde_json::{Value, json};
use crate::telemetry::converters::{AttrValue, from_log_value, json_number, to_log_value};
#[rstest]
#[case::nil(json!(null), json!(null))]
#[case::string(json!("hello"), json!("hello"))]
#[case::bool(json!(true), json!(true))]
#[case::float64(json!(123.456), json!(123.456))]
#[case::int_to_int64(json!(123), json!(123))]
#[case::slice_of_mixed_types(json!([1.0, true, "foo"]), json!([1.0, true, "foo"]))]
#[case::map(json!({"foo": "bar", "baz": 123.0}), json!({"foo": "bar", "baz": 123.0}))]
#[case::nested_structure(json!({"list": [{"a": 1.0}]}), json!({"list": [{"a": 1.0}]}))]
fn test_converters_round_trip(#[case] val: Value, #[case] want: Value) {
let got = from_log_value(&to_log_value(&val));
assert_eq!(got, want);
if let (Value::Number(g), Value::Number(w)) = (&got, &want) {
assert_eq!(g.is_f64(), w.is_f64());
}
}
#[test]
fn test_converters_round_trip_json_number_beyond_float64_keeps_its_text() {
let text = "9".repeat(401);
assert_eq!(json_number(&text), AttrValue::String(text.clone()));
assert_eq!(from_log_value(&json_number(&text)), Value::String(text));
}
#[rstest]
#[case::bool(AttrValue::BoolSlice(vec![true, false]), json!([true, false]))]
#[case::int64(AttrValue::Int64Slice(vec![1, 2]), json!([1, 2]))]
#[case::float64(AttrValue::Float64Slice(vec![1.5, 2.5]), json!([1.5, 2.5]))]
#[case::string(AttrValue::StringSlice(vec!["a".into(), "b".into()]), json!(["a", "b"]))]
#[case::bytes(AttrValue::ByteSlice(vec![1, 2]), json!([1, 2]))]
fn test_from_log_value_typed_slices(#[case] val: AttrValue, #[case] want: Value) {
assert_eq!(from_log_value(&val), want);
}