/// <summary>FFI JSON serialization extension methods and options</summary>
internal static class FfiJsonExtensions {

    /// <summary>Global JsonSerializerOptions for FFI marshalling with relaxed numeric handling.
    /// Supports: enum-to-snake_case conversion, ignoring default values, and reading numeric values from strings.
    /// Used by both trait bridges and callback deserialization.</summary>
    public static readonly JsonSerializerOptions FfiJsonOptions = new()
    {
        Converters = { new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseLower) },
        DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
        NumberHandling = JsonNumberHandling.AllowReadingFromString
    };

    /// <summary>Serialize any object to JSON for FFI marshalling</summary>
    internal static string ToFfiJson<T>(this T value) {
        return JsonSerializer.Serialize(value, FfiJsonOptions);
    }

}
