using Newtonsoft.Json;

namespace FNZCM.BlazorWasm.UI.Components.FnzBootstrap.Modal
{
    public enum BackdropMode
    {
        On,
        Off,
        Static
    }

    public class BackdropsJsonConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType) 
            => objectType == typeof(BackdropMode);

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 
            => throw new NotImplementedException();

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var v = (BackdropMode)value;
            writer.WriteValue(v switch
            {
                BackdropMode.On => true,
                BackdropMode.Off => false,
                BackdropMode.Static => "static",
                _ => null,
            });
        }
    }
}
