using System.Text.Json;
using System.Text.Json.Serialization;

namespace ZB.MOM.WW.ScadaBridge.Transport.Serialization;

/// <summary>
/// Canonical <see cref="JsonSerializerOptions"/> shared by every component that
/// reads or writes a bundle content payload.
/// <para>
/// <b>Important — unknown-property tolerance:</b>
/// <see cref="JsonUnmappedMemberHandling"/> is left at its default
/// (<c>Skip</c>); setting it to <c>Disallow</c> would break backward-
/// compatible deserialization of older bundles, which may carry a top-level
/// <c>apiKeys</c> array and/or <c>ApprovedApiKeyIds</c> fields inside
/// <c>apiMethods[]</c> entries. That tolerance is load-bearing and must be
/// preserved.
/// </para>
/// <para>
/// <b><c>WhenWritingNull</c>:</b> new bundles never emit a top-level
/// <c>ApiKeys</c> property (it defaults to <c>null</c> on
/// <see cref="BundleContentDto"/>); <c>WhenWritingNull</c> ensures the field
/// is omitted entirely from the JSON so the wire format stays clean.
/// </para>
/// </summary>
internal static class BundleJsonOptions
{
    /// <summary>
    /// The single shared <see cref="JsonSerializerOptions"/> instance for
    /// all bundle content serialization and deserialization.
    /// </summary>
    internal static readonly JsonSerializerOptions Default = new()
    {
        WriteIndented = false,
        DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
        Converters = { new JsonStringEnumConverter() },
    };
}
