// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do one of these:
//
//    using QuickType;
//
//    var payload = Payload.FromJson(jsonString);
//    var envelope = Envelope.FromJson(jsonString);
//    var payloadT = PayloadT.FromJson(jsonString);
//    var t = T.FromJson(jsonString);
//    var envelopeT = EnvelopeT.FromJson(jsonString);
//    var payloadT1 = PayloadT1.FromJson(jsonString);
//    var t1 = T1.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Collections.Generic;

    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class PayloadT
    {
        [JsonProperty("data")]
        public Dictionary<string, object> Data { get; set; }

        [JsonProperty("kind")]
        public string Kind { get; set; }
    }

    public partial class EnvelopeT
    {
        [JsonProperty("data")]
        public PayloadT1 Data { get; set; }

        [JsonProperty("dst")]
        public string[] Dst { get; set; }

        [JsonProperty("id")]
        public string Id { get; set; }

        [JsonProperty("src")]
        public string Src { get; set; }

        [JsonProperty("t")]
        public double T { get; set; }

        [JsonProperty("ttl")]
        public double Ttl { get; set; }

        [JsonProperty("v")]
        public V V { get; set; }
    }

    public partial class PayloadT1
    {
        [JsonProperty("data")]
        public Dictionary<string, object> Data { get; set; }

        [JsonProperty("kind")]
        public string Kind { get; set; }
    }

    public enum V { A };

    public partial class Payload
    {
        public static PayloadT FromJson(string json) => JsonConvert.DeserializeObject<PayloadT>(json, QuickType.Converter.Settings);
    }

    public partial class Envelope
    {
        public static EnvelopeT FromJson(string json) => JsonConvert.DeserializeObject<EnvelopeT>(json, QuickType.Converter.Settings);
    }

    public partial class PayloadT
    {
        public static PayloadT FromJson(string json) => JsonConvert.DeserializeObject<PayloadT>(json, QuickType.Converter.Settings);
    }

    public class T
    {
        public static Dictionary<string, object> FromJson(string json) => JsonConvert.DeserializeObject<Dictionary<string, object>>(json, QuickType.Converter.Settings);
    }

    public partial class EnvelopeT
    {
        public static EnvelopeT FromJson(string json) => JsonConvert.DeserializeObject<EnvelopeT>(json, QuickType.Converter.Settings);
    }

    public partial class PayloadT1
    {
        public static PayloadT1 FromJson(string json) => JsonConvert.DeserializeObject<PayloadT1>(json, QuickType.Converter.Settings);
    }

    public class T1
    {
        public static Dictionary<string, object> FromJson(string json) => JsonConvert.DeserializeObject<Dictionary<string, object>>(json, QuickType.Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this PayloadT self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
        public static string ToJson(this EnvelopeT self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
        public static string ToJson(this Dictionary<string, object> self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
        public static string ToJson(this PayloadT1 self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
    }

    internal static class Converter
    {
        public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
        {
            MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
            DateParseHandling = DateParseHandling.None,
            Converters =
            {
                VConverter.Singleton,
                new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
            },
        };
    }

    internal class VConverter : JsonConverter
    {
        public override bool CanConvert(Type t) => t == typeof(V) || t == typeof(V?);

        public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null) return null;
            var value = serializer.Deserialize<string>(reader);
            if (value == "A")
            {
                return V.A;
            }
            throw new Exception("Cannot unmarshal type V");
        }

        public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
        {
            if (untypedValue == null)
            {
                serializer.Serialize(writer, null);
                return;
            }
            var value = (V)untypedValue;
            if (value == V.A)
            {
                serializer.Serialize(writer, "A");
                return;
            }
            throw new Exception("Cannot marshal type V");
        }

        public static readonly VConverter Singleton = new VConverter();
    }
}
