#[macro_export]
macro_rules! fields {
    ($($name:expr => $value:expr),* $(,)?) => {
        vec![
            $(
                $crate::Field::new($name, $value),
            )*
        ]
    };
}

#[cfg(test)]
mod tests {
    use crate::types::{Field, FieldValue};

    #[test]
    fn test_fields_macro_basic() {
        let fields: Vec<Field> = fields![
            "id" => 1_i32,
            "name" => "test",
        ];

        assert_eq!(fields.len(), 2);
        assert_eq!(fields[0].name, "id");
        assert_eq!(fields[1].name, "name");

        match &fields[0].value {
            FieldValue::Int32(v) => assert_eq!(*v, 1),
            _ => panic!("expected Int32"),
        }

        match &fields[1].value {
            FieldValue::String(v) => assert_eq!(v, "test"),
            _ => panic!("expected String"),
        }
    }

    #[test]
    fn test_fields_macro_with_options() {
        let fields: Vec<Field> = fields![
            "id" => 1_i64,
            "description" => None::<String>,
            "active" => Some(true),
        ];

        assert_eq!(fields.len(), 3);

        match &fields[1].value {
            FieldValue::Null => {}
            _ => panic!("expected Null"),
        }

        match &fields[2].value {
            FieldValue::Bool(v) => assert!(*v),
            _ => panic!("expected Bool"),
        }
    }

    #[test]
    fn test_fields_macro_all_types() {
        let fields: Vec<Field> = fields![
            "int32" => 42_i32,
            "int64" => 42_i64,
            "float32" => 42.5_f32,
            "float64" => 42.5_f64,
            "bool" => true,
            "string" => "hello".to_string(),
            "str" => "world",
            "bytes" => vec![1_u8, 2, 3],
        ];

        assert_eq!(fields.len(), 8);
    }

    #[test]
    fn test_fields_macro_empty() {
        let fields: Vec<Field> = fields![];
        assert!(fields.is_empty());
    }

    #[test]
    fn test_fields_macro_trailing_comma() {
        let fields: Vec<Field> = fields![
            "id" => 1_i32,
            "name" => "test",
        ];
        assert_eq!(fields.len(), 2);
    }
}
